From 70d690f3e9fea1cd59dbca074633e8488de6ef48 Mon Sep 17 00:00:00 2001 From: niharlcp1 Date: Thu, 16 Oct 2008 04:18:32 +0000 Subject: [PATCH] Test Scripts For TableDef --- test/dbapi/TableDef/Makefile | 67 ++++++++++++++++++++++++++++++++ test/dbapi/TableDef/csql.conf | 62 +++++++++++++++++++++++++++++ test/dbapi/TableDef/dupfieldname.c | 29 ++++++++++++++ test/dbapi/TableDef/fieldcasesensitive.c | 28 +++++++++++++ test/dbapi/TableDef/fieldcount1.c | 23 +++++++++++ test/dbapi/TableDef/fieldcount2.c | 33 ++++++++++++++++ test/dbapi/TableDef/fieldcount3.c | 39 +++++++++++++++++++ test/dbapi/TableDef/fieldname1.c | 42 ++++++++++++++++++++ test/dbapi/TableDef/fieldname2.c | 28 +++++++++++++ test/dbapi/TableDef/fieldname3.c | 59 ++++++++++++++++++++++++++++ test/dbapi/TableDef/tablename1.c | 27 +++++++++++++ test/dbapi/TableDef/tuplesize1.c | 28 +++++++++++++ test/dbapi/TableDef/withoutfieldname.c | 26 +++++++++++++ 13 files changed, 491 insertions(+) create mode 100644 test/dbapi/TableDef/Makefile create mode 100644 test/dbapi/TableDef/csql.conf create mode 100644 test/dbapi/TableDef/dupfieldname.c create mode 100644 test/dbapi/TableDef/fieldcasesensitive.c create mode 100644 test/dbapi/TableDef/fieldcount1.c create mode 100644 test/dbapi/TableDef/fieldcount2.c create mode 100644 test/dbapi/TableDef/fieldcount3.c create mode 100644 test/dbapi/TableDef/fieldname1.c create mode 100644 test/dbapi/TableDef/fieldname2.c create mode 100644 test/dbapi/TableDef/fieldname3.c create mode 100644 test/dbapi/TableDef/tablename1.c create mode 100644 test/dbapi/TableDef/tuplesize1.c create mode 100644 test/dbapi/TableDef/withoutfieldname.c diff --git a/test/dbapi/TableDef/Makefile b/test/dbapi/TableDef/Makefile new file mode 100644 index 00000000..09ea0ec2 --- /dev/null +++ b/test/dbapi/TableDef/Makefile @@ -0,0 +1,67 @@ + +: +OSNAME = $(shell uname -s) +PlatForm=supported + +ifeq ($(OSNAME), SunOS) +CPlus = CC +CPlusFlags = -O2 -w -mt -xarch=v8 +SYSLIBS=-ldl -lnsl -lsocket -lposix4 +else +ifeq ($(OSNAME), Linux) +CPlus = g++ +CPlusFlags = -g -w +SYSLIBS= -rdynamic -lrt -lpthread -lcrypt +else +PlatForm=notsupported +all: + echo "CSQL is not supported on $(OSNAME) platform" +endif +endif + +INCL= -I$(CSQL_INSTALL_ROOT)/include +LIBS= -L$(CSQL_INSTALL_ROOT)/lib -lcsql + +TARGETS = \ + test001 \ + test002 \ + test003 \ + test004 \ + test005 \ + test006 \ + test007 \ + test008 \ + test009 \ + test010 \ + test011 + + +ifeq ($(PlatForm), supported) +all: $(TARGETS) +endif + +test001: fieldname1.c + $(CPlus) $(CPlusFlags) -o $@ $< $(INCL) $(LIBS) $(SYSLIBS) +test002: fieldname2.c + $(CPlus) $(CPlusFlags) -o $@ $< $(INCL) $(LIBS) $(SYSLIBS) +test003: fieldname3.c + $(CPlus) $(CPlusFlags) -o $@ $< $(INCL) $(LIBS) $(SYSLIBS) +test004: withoutfieldname.c + $(CPlus) $(CPlusFlags) -o $@ $< $(INCL) $(LIBS) $(SYSLIBS) +test005: dupfieldname.c + $(CPlus) $(CPlusFlags) -o $@ $< $(INCL) $(LIBS) $(SYSLIBS) +test006: fieldcount1.c + $(CPlus) $(CPlusFlags) -o $@ $< $(INCL) $(LIBS) $(SYSLIBS) +test007: fieldcount2.c + $(CPlus) $(CPlusFlags) -o $@ $< $(INCL) $(LIBS) $(SYSLIBS) +test008: fieldcount3.c + $(CPlus) $(CPlusFlags) -o $@ $< $(INCL) $(LIBS) $(SYSLIBS) +test009: fieldcasesensitive.c + $(CPlus) $(CPlusFlags) -o $@ $< $(INCL) $(LIBS) $(SYSLIBS) +test010: tablename1.c + $(CPlus) $(CPlusFlags) -o $@ $< $(INCL) $(LIBS) $(SYSLIBS) +test011: tuplesize1.c + $(CPlus) $(CPlusFlags) -o $@ $< $(INCL) $(LIBS) $(SYSLIBS) +clean: + rm -f $(TARGETS) + diff --git a/test/dbapi/TableDef/csql.conf b/test/dbapi/TableDef/csql.conf new file mode 100644 index 00000000..fcad4cfc --- /dev/null +++ b/test/dbapi/TableDef/csql.conf @@ -0,0 +1,62 @@ +# CSQL System Configuration File + +#####################################Server Section######################## +#Important: For Server section parameters, make sure that the value is same for the +# server process and all the csql client process which connects to it. otherwise, +# behavior is undefined + +# Page size. Each database is logically divided into pages and allocation happens +# in this unit of pages. Increasing this value will reduce frequent allocation of pages. +PAGE_SIZE= 8192 + +#Total number of client process which can connect and work with the +# database concurrently +MAX_PROCS = 100 + +# Maximum size of the system database. +MAX_SYS_DB_SIZE=10485760 + +#Maximum size of the user database file. +MAX_DB_SIZE=335544320 + +#Shared memory key to be used by the system to create and locate system database. +SYS_DB_KEY=7117 + +#Shared memory key to be used by the system to create and locate user database. +USER_DB_KEY=1771 + +#Give full path for the log file where important system actions are stored. +LOG_FILE=/tmp/log/csql/log.out + +#The virtual memory start address at which the shared memory segment +# will be created and attached. +MAP_ADDRESS=400000000 + +#Important: For Server section parameters, make sure that the value is same for the +# server process and all the csql client process which connects to it. otherwise, +# behavior is undefined +#####################################Client Section######################## + +#Mutex timeout interval seconds +MUTEX_TIMEOUT_SECS=0 +MUTEX_TIMEOUT_USECS=5000 +MUTEX_TIMEOUT_RETRIES=10 + +#Lock timeout interval seconds +LOCK_TIMEOUT_SECS=0 +LOCK_TIMEOUT_USECS=5000 +LOCK_TIMEOUT_RETRIES=10 + +#####################################Cache Section######################## + +#Whether to enable caching of tables from target database +CACHE_TABLE=false + +#DSN Name to connect to the target database. +#This should be present in ~/odbc.ini file +DSN=myodbc3 + +#Give full path for the file where all the cached table information is stored +TABLE_CONFIG_FILE=/tmp/csql/csqltable.conf + +#####################################End Section######################## diff --git a/test/dbapi/TableDef/dupfieldname.c b/test/dbapi/TableDef/dupfieldname.c new file mode 100644 index 00000000..92d00356 --- /dev/null +++ b/test/dbapi/TableDef/dupfieldname.c @@ -0,0 +1,29 @@ +//Should not allow duplicate field names in one table +#include +int main() +{ + Connection conn; + DbRetVal rv = conn.open("root", "manager"); + if (rv != OK) return 1; + DatabaseManager *dbMgr = conn.getDatabaseManager(); + if (dbMgr == NULL) { printf("Auth failed\n"); return 2;} + + TableDef tabDef; + //int test=0; + tabDef.addField("f1", typeInt, 0, NULL, true); + rv=(DbRetVal)tabDef.addField("f1", typeInt); + if(rv==0) + { + printf("Test failed with return value %d\n",rv); + return rv; + } + printf("test passed\n"); + dbMgr->createTable("t1", tabDef); + dbMgr->dropTable("t1"); + conn.close(); + return 0; +} + +//3298:3086821072:TableDef.cxx:40:Field f_1 already Exists +//Table created with field name f_1 only + diff --git a/test/dbapi/TableDef/fieldcasesensitive.c b/test/dbapi/TableDef/fieldcasesensitive.c new file mode 100644 index 00000000..01f068ef --- /dev/null +++ b/test/dbapi/TableDef/fieldcasesensitive.c @@ -0,0 +1,28 @@ +//Create table with fieldname as "EMP" and "emp". it should succeed. +#include +int main() +{ + Connection conn; + DbRetVal rv = conn.open("root", "manager"); + if (rv != OK) return 1; + DatabaseManager *dbMgr = conn.getDatabaseManager(); + if (dbMgr == NULL) { printf("Auth failed\n"); return 2;} + + TableDef tabDef; + tabDef.addField("EMP", typeInt, 0, NULL, true); + rv=(DbRetVal)tabDef.addField("emp", typeInt); + if(rv!=0) + { + printf("Test Failed with return value %d\n",rv); + return rv; + } + + dbMgr->createTable("t1", tabDef); + printf("Table created\n"); + printf("test Passed\n"); + dbMgr->dropTable("t1"); + conn.close(); + return 0; +} + + diff --git a/test/dbapi/TableDef/fieldcount1.c b/test/dbapi/TableDef/fieldcount1.c new file mode 100644 index 00000000..6347795f --- /dev/null +++ b/test/dbapi/TableDef/fieldcount1.c @@ -0,0 +1,23 @@ +//100 times addField f1 and dropField f1. getFldCount() should return 0 +#include +int main() +{ + Connection conn; + DbRetVal rv = conn.open("root", "manager"); + if (rv != OK) return 1; + DatabaseManager *dbMgr = conn.getDatabaseManager(); + if (dbMgr == NULL) { printf("Auth failed\n"); return 2;} + + TableDef tabDef; + for (int i=0;i<100;i++) + { + tabDef.addField("f1", typeInt); + tabDef.dropField("f1"); + } + int fieldcount=tabDef.getFieldCount(); + printf("Number of Fields = %d\n",fieldcount); + printf("Test Passed\n"); + conn.close(); + return 0; +} + diff --git a/test/dbapi/TableDef/fieldcount2.c b/test/dbapi/TableDef/fieldcount2.c new file mode 100644 index 00000000..09b2d7ca --- /dev/null +++ b/test/dbapi/TableDef/fieldcount2.c @@ -0,0 +1,33 @@ +//100 times addField f1 and dropField f1. getFieldCount() should return 0 +//and table creation should fail saying no fields in tabledef +#include +int main() +{ + Connection conn; + DbRetVal rv = conn.open("root", "manager"); + if (rv != OK) return 1; + DatabaseManager *dbMgr = conn.getDatabaseManager(); + if (dbMgr == NULL) { printf("Auth failed\n"); return 2;} + + TableDef tabDef; + for (int i=0;i<100;i++) + { + tabDef.addField("f1", typeInt); + tabDef.dropField("f1"); + } + int fieldcount=tabDef.getFieldCount(); + printf("Number of Fields = %d\n",fieldcount); + rv=dbMgr->createTable("t1", tabDef); + if(rv==OK) + { + printf("Table created without Fields\n"); + printf("Test failed\n"); + dbMgr->dropTable("t1"); + return 3; + } + + dbMgr->dropTable("t1"); + conn.close(); + return 0; +} + diff --git a/test/dbapi/TableDef/fieldcount3.c b/test/dbapi/TableDef/fieldcount3.c new file mode 100644 index 00000000..ac78f177 --- /dev/null +++ b/test/dbapi/TableDef/fieldcount3.c @@ -0,0 +1,39 @@ +//Create table with 1024 fields and call getFldCount() +//and check return value is 1024 +#include +int main() +{ + Connection conn; + DbRetVal rv = conn.open("root", "manager"); + if (rv != OK) return 1; + DatabaseManager *dbMgr = conn.getDatabaseManager(); + if (dbMgr == NULL) { printf("Auth failed\n"); return 2;} + int test; + TableDef tabDef; + char str[6]="f",field[6]; + for (int i=1;i<=1024;i++) + { + sprintf(field,"%s%d",str,i); + test=tabDef.addField(field, typeInt); + if(test!=0) + { + printf("Field f%d could not be created",i); + return test; + } + } + int fieldcount=tabDef.getFieldCount(); + printf("Number of Fields = %d\n",fieldcount); + rv=dbMgr->createTable("t1", tabDef); + if(rv!=OK) + { + printf("Table creation Failed\n"); + printf("Test failed\n"); + return 3; + } + printf("Table created \n"); + printf("Test passed\n"); + dbMgr->dropTable("t1"); + conn.close(); + return 0; +} + diff --git a/test/dbapi/TableDef/fieldname1.c b/test/dbapi/TableDef/fieldname1.c new file mode 100644 index 00000000..bfd10c75 --- /dev/null +++ b/test/dbapi/TableDef/fieldname1.c @@ -0,0 +1,42 @@ +//Create table with the field name made up of special characters other than +//underscore. it should not be allowed. +#include +int main() +{ + Connection conn; + DbRetVal rv = conn.open("root", "manager"); + if (rv != OK) return 1; + DatabaseManager *dbMgr = conn.getDatabaseManager(); + if (dbMgr == NULL) { printf("Auth failed\n"); return 2;} + + TableDef tabDef; + int i=0; + rv=(DbRetVal)tabDef.addField("f-2", typeInt); + if(rv!=OK) i++; + rv=(DbRetVal)tabDef.addField("2f", typeInt); + if(rv!=OK) i++; + rv=(DbRetVal)tabDef.addField("f2@", typeInt); + if(rv!=OK) i++; + rv=(DbRetVal)tabDef.addField("_f2#", typeInt); + if(rv!=OK) i++; + rv=(DbRetVal)tabDef.addField("$f2", typeInt); + if(rv!=OK) i++; + rv=(DbRetVal)tabDef.addField("$@*#", typeInt); + if(rv!=OK) i++; + + if(i){printf(" Test Failed \n"); return i;} + + rv=dbMgr->createTable("t1", tabDef); + if(rv==OK) + { + printf("Allowing fieldnames made up of all special characters\n"); + printf("Test failed\n"); + dbMgr->dropTable("t1"); + return 3; + } + + printf("Test Passed\n"); + conn.close(); + return 0; +} +//Table is created and allowing field names with special characters other than underscores also diff --git a/test/dbapi/TableDef/fieldname2.c b/test/dbapi/TableDef/fieldname2.c new file mode 100644 index 00000000..e9eb0f37 --- /dev/null +++ b/test/dbapi/TableDef/fieldname2.c @@ -0,0 +1,28 @@ +//Should not allow field names more than 64 character +#include +int main() +{ + Connection conn; + DbRetVal rv = conn.open("root", "manager"); + if (rv != OK) return 1; + DatabaseManager *dbMgr = conn.getDatabaseManager(); + if (dbMgr == NULL) { printf("Auth failed\n"); return 2;} + + TableDef tabDef; + + tabDef.addField("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklabc", typeInt, 0, NULL, true); + rv=dbMgr->createTable("t1", tabDef); + if(rv==OK) + { + printf("Allowing fieldname more than 64 character\n"); + printf("Test Failed\n"); + dbMgr->dropTable("t1"); + return 3; + } + printf("Test Passed\n"); + conn.close(); + return 0; +} + +//Table is created and allowing fieldnames with more than 64 characters + diff --git a/test/dbapi/TableDef/fieldname3.c b/test/dbapi/TableDef/fieldname3.c new file mode 100644 index 00000000..a0e09ae7 --- /dev/null +++ b/test/dbapi/TableDef/fieldname3.c @@ -0,0 +1,59 @@ +//addField f1, dropField f1 and then addField f1 with notnull flag set, +//table creation should succeed and it should make the f1 field notnull +#include +int main() +{ + Connection conn; + DbRetVal rv = conn.open("root", "manager"); + if (rv != OK) return 1; + DatabaseManager *dbMgr = conn.getDatabaseManager(); + if (dbMgr == NULL) { printf("Auth failed\n"); return 2;} + + TableDef tabDef; + + tabDef.addField("f1", typeInt); + tabDef.dropField("f1"); + tabDef.addField("f1", typeInt, 0, NULL, true); + rv=dbMgr->createTable("t1", tabDef); + if(rv!=OK) + { + printf("Table creation failed\n"); + printf("Test Failed\n"); + dbMgr->dropTable("t1"); + return 3; + } + printf("Table created\n"); + + Table *table = dbMgr->openTable("t1"); + if (table == NULL) + { + printf("Unable to open table\n"); + dbMgr->dropTable("t1"); + conn.close(); + return -1; + } +// int id; +// table->bindFld("f1",&id); + + conn.startTransaction(); + rv=table->insertTuple(); + if(rv==OK) + { + printf("NULL value inserted in NOTNULL field\n"); + printf("Test Failed\n"); + conn.commit(); + dbMgr->closeTable(table); + dbMgr->dropTable("t1"); + return 4; + } + conn.commit(); + printf("NULL value can not be stored\n"); + printf("Test passed\n"); + dbMgr->closeTable(table); + dbMgr->dropTable("t1"); + conn.close(); + return 0; +} + + + diff --git a/test/dbapi/TableDef/tablename1.c b/test/dbapi/TableDef/tablename1.c new file mode 100644 index 00000000..bc2a9862 --- /dev/null +++ b/test/dbapi/TableDef/tablename1.c @@ -0,0 +1,27 @@ +//create table with the name made up of special characters other than underscores.It should fail +#include +int main() +{ + Connection conn; + DbRetVal rv = conn.open("root", "manager"); + if (rv != OK) return 1; + DatabaseManager *dbMgr = conn.getDatabaseManager(); + if (dbMgr == NULL) { printf("Auth failed\n"); return 2;} + + TableDef tabDef; + + tabDef.addField("f1", typeInt, 0, NULL, true); + rv=dbMgr->createTable("t-1",tabDef); + if(rv==OK) + { + printf("Test Failed\n"); + rv=dbMgr->dropTable("t-1"); + return 3; + } + printf("Test Passed\n"); + conn.close(); + return 0; +} + +//Table creating with name made up of any special character + diff --git a/test/dbapi/TableDef/tuplesize1.c b/test/dbapi/TableDef/tuplesize1.c new file mode 100644 index 00000000..e4a964c8 --- /dev/null +++ b/test/dbapi/TableDef/tuplesize1.c @@ -0,0 +1,28 @@ +//addfield f1 int, addField f2 char(10), addField f3 int. +//Check the getTupleSize() return value. It should be 20 +#include +int main() +{ + Connection conn; + DbRetVal rv = conn.open("root", "manager"); + if (rv != OK) return 1; + DatabaseManager *dbMgr = conn.getDatabaseManager(); + if (dbMgr == NULL) { printf("Auth failed\n"); return 2;} + + TableDef tabDef; + + tabDef.addField("f1", typeInt, 0, NULL, true); + tabDef.addField("f2", typeString,10); + tabDef.addField("f3", typeInt); + + dbMgr->createTable("t1", tabDef); + printf("Table created\n"); + size_t sizeofTuple = os::align(tabDef.getTupleSize()); + printf("Size of 1 tuple is %d\n",sizeofTuple); + + dbMgr->dropTable("t1"); + conn.close(); + return 0; +} + + diff --git a/test/dbapi/TableDef/withoutfieldname.c b/test/dbapi/TableDef/withoutfieldname.c new file mode 100644 index 00000000..ace9afb5 --- /dev/null +++ b/test/dbapi/TableDef/withoutfieldname.c @@ -0,0 +1,26 @@ +//create table without fields. it should be failed +#include +int main() +{ + Connection conn; + DbRetVal rv = conn.open("root", "manager"); + if (rv != OK) return 1; + DatabaseManager *dbMgr = conn.getDatabaseManager(); + if (dbMgr == NULL) { printf("Auth failed\n"); return 2;} + + TableDef tabDef; + + rv=dbMgr->createTable("t1", tabDef); + if(rv==OK) + { + printf("Table created without Fields\n"); + printf("Test failed\n"); + dbMgr->dropTable("t1"); + return 3; + } + + printf("Test Passed\n"); + conn.close(); + return 0; +} + -- 2.11.4.GIT