2 /**************************************************
3 opengate server test program
5 Copyright (C) 2005 Opengate Project Team
6 Written by Yoshiaki Watanabe
7 Modified Katsuhiko Eguchi, 2005
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 Email: watanaby@is.saga-u.ac.jp
24 **************************************************/
26 #include "opengatesrv.h"
29 /********************/
31 /********************/
32 int main(int argc, char **argv)
34 char userid[USERMAXLN];
35 char clientAddr4[ADDRMAXLN];
36 char macAddr[ADDRMAXLN];
37 char language[WORDMAXLN];
45 printf("This is a test program for accessing sqlite db\n");
47 /******************************************/
48 /* First Test: stand-alone sqlite3 access */
49 printf("FIRST TEST:\n");
50 printf(" create and access /tmp/testsqlite3.db \n");
51 printf(" please remove /tmp/testsqlite3.db after test\n");
53 printf("sqlite3_open\n");
54 if(sqlite3_open("/tmp/testsqlite3.db",&db)!=SQLITE_OK){
55 printf("ERR at %s#%d: sqlite3_open\n",__FILE__,__LINE__);
60 printf("sqlite3_exec(create)\n");
61 if(sqlite3_exec(db, "CREATE TABLE testTable (id TEXT PRIMARY KEY,test TEXT)",
62 NULL, NULL, &pErrMsg)!=SQLITE_OK){
63 printf("ERR at %s#%d: sqlite3_exec: %s\n",__FILE__,__LINE__,pErrMsg);
64 printf(" Remove '/tmp/testsqlite3.db' and retry, when 'ERR..testTable already exists'\n");
69 printf("sqlite3_exec(insert)\n");
70 if(sqlite3_exec(db, "INSERT INTO testTable (test) values ('tttt')",
71 NULL, NULL, &pErrMsg)!=SQLITE_OK){
72 printf("ERR at %s#%d: sqlite3_exec: %s\n",__FILE__,__LINE__,pErrMsg);
77 printf("sqlite3_prepare\n");
78 if(sqlite3_prepare(db, "SELECT test FROM testTable WHERE test='tttt'",
79 BUFFMAXLN, &stmt, NULL)!=SQLITE_OK){
80 printf("ERR at %s#%d: sqlite3_prepare:%s\n",__FILE__,__LINE__,
84 sqlite3_finalize(stmt);
89 printf("sqlite3_step\n");
90 if(sqlite3_step(stmt)==SQLITE_ROW){
91 printf("%s", (char*)sqlite3_column_text(stmt, 0));
92 printf(" <== should be 'tttt'\n");
94 sqlite3_finalize(stmt);
100 sqlite3_finalize(stmt);
103 printf("end of first test\n\n");
105 /************************************/
106 /* Second Test: get opengate config */
108 printf("SECOND TEST\n");
109 printf("create and access db file defined in conf file\n");
111 /* prepare config file */
115 errToSyslog(atoi(GetConfValue("Syslog/Enable")));
116 openlog(argv[0], LOG_PID, atoi(GetConfValue("Syslog/Facility")));
121 /* put session begin to db */
122 PutSessionBeginToDb("testcookie", "testuser",
123 "192.168.0.123", "2001::1",
128 /* put session end to db */
129 PutSessionEndToDb("testcookie", "HTTP");
131 /* get data from db */
132 GetSessionInfoFromDb("testcookie", userid,
133 clientAddr4, macAddr,
134 &duration, &durationEntered, language);
136 /* dump getting data */
137 printf("%s, %s, %s, %d, %d, %s\n", userid, clientAddr4, macAddr,
138 duration, durationEntered, language);
140 printf("<== sholud be 'testuser, 192.168.0.123, 00:11:22:33:44:55, 600, 600, ja'\n");
142 printf("end of second test\n\n");