/***************************************************************** * test-substabce.c the executed module contains test of * integer's types. As a result of * its executing is added entries to the sql-table * called "substances" have kind, class, id atributes. * * Copyright (C) 2009 Andrey Y. Rjavskov(aka rjaan) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * *****************************************************************/ #include "test-common.h" #include "test-config.h" static unsigned short subs_kindmax; static unsigned long int subs_classmax; static unsigned long long int subs_idmax; static int substance_add ( PGconn* testdb, unsigned long long int id ); int main( int argc, char** argv ) { PGconn* testdb; unsigned long long int subs_id; unsigned int srandom_value=(int)(time(0)/(365*24*3600)) + (getpid()<<8); srandom( srandom_value ); subs_kindmax = SQLTYPE_LIMIT_SMALINT - 1; subs_classmax = SQLTYPE_LIMIT_INTEGER - 1; // subs_idmax = SQLTYPE_LIMIT_BIGINT - 1; testdb = upg_connect_db ( BT_DBHOST, BT_DBPORT, BT_DBNAME, NULL, NULL ); if ( !testdb ) { return EXIT_FAILURE; } if ( upg_sqlexec ( testdb, "DELETE FROM substances;" ) == -EXIT_FAILURE ) { return -EXIT_FAILURE; } test_begin ( argv[0] ); for ( subs_id=1; subs_id < 100000; subs_id++ ) { if ( substance_add ( testdb, subs_id ) == -EXIT_FAILURE ) break; } test_done(); upg_disconnect_db ( testdb ); return EXIT_SUCCESS; } static int substance_add ( PGconn* testdb, unsigned long long int id ) { unsigned long int rand_val = random(); unsigned short subs_kind = !(rand_val%subs_kindmax) ? 1 : rand_val%subs_kindmax ; unsigned long int subs_class = !(rand_val%subs_classmax) ? 1 : rand_val%subs_classmax ; if ( upg_sqlexec ( testdb, "INSERT INTO substances(kind,class,id) VALUES(%d,%ld,%ld);", subs_kind, subs_class, id ) == -EXIT_FAILURE ) { return -EXIT_FAILURE; } test_go( id, 50000 ); return EXIT_SUCCESS; } /*oef*/