Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief UBF Field table database tests - client, IPC part
0003  *
0004  * @file atmiclt50ipc.c
0005  */
0006 /* -----------------------------------------------------------------------------
0007  * Enduro/X Middleware Platform for Distributed Transaction Processing
0008  * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
0009  * Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved.
0010  * This software is released under one of the following licenses:
0011  * AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
0012  * See LICENSE file for full text.
0013  * -----------------------------------------------------------------------------
0014  * AGPL license:
0015  *
0016  * This program is free software; you can redistribute it and/or modify it under
0017  * the terms of the GNU Affero General Public License, version 3 as published
0018  * by the Free Software Foundation;
0019  *
0020  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
0021  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0022  * PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
0023  * for more details.
0024  *
0025  * You should have received a copy of the GNU Affero General Public License along 
0026  * with this program; if not, write to the Free Software Foundation, Inc.,
0027  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0028  *
0029  * -----------------------------------------------------------------------------
0030  * A commercial use license is available from Mavimax, Ltd
0031  * contact@mavimax.com
0032  * -----------------------------------------------------------------------------
0033  */
0034 #include <string.h>
0035 #include <stdio.h>
0036 #include <stdlib.h>
0037 #include <memory.h>
0038 #include <math.h>
0039 
0040 #include <atmi.h>
0041 #include <ubf.h>
0042 #include <ndebug.h>
0043 #include <test.fd.h>
0044 #include <ndrstandard.h>
0045 #include <nstopwatch.h>
0046 #include <fcntl.h>
0047 #include <unistd.h>
0048 #include <nstdutil.h>
0049 #include <cgreen/cgreen.h>
0050 #include "test50.h"
0051 /*---------------------------Externs------------------------------------*/
0052 /*---------------------------Macros-------------------------------------*/
0053 /*---------------------------Enums--------------------------------------*/
0054 /*---------------------------Typedefs-----------------------------------*/
0055 /*---------------------------Globals------------------------------------*/
0056 /*---------------------------Statics------------------------------------*/
0057 /*---------------------------Prototypes---------------------------------*/
0058 
0059 
0060 /**
0061  * Basic preparation before the test
0062  */
0063 exprivate void basic_setup(void)
0064 {
0065 
0066 }
0067 
0068 exprivate void basic_teardown(void)
0069 {
0070 
0071 }
0072 
0073 /**
0074  * Get transaction object..
0075  * @param txn
0076  */
0077 exprivate void get_tran(EDB_txn **txn)
0078 {
0079     EDB_env * dbenv = NULL;
0080     EDB_dbi *dbi_id = NULL, *dbi_nm = NULL;
0081     
0082     /* get DB Env */
0083     dbenv = Bfldddbgetenv(&dbi_id, &dbi_nm);
0084     
0085     assert_not_equal(dbenv, NULL);
0086     assert_not_equal(dbi_id, NULL);
0087     assert_not_equal(dbi_nm, NULL);
0088     
0089     /* begin transaction */
0090     assert_equal(edb_txn_begin(dbenv, NULL, 0, txn), EXSUCCEED);
0091 }
0092 
0093 /**
0094  * Local testing of the UBF DB
0095  */
0096 Ensure(ubfdb_setup)
0097 {
0098     EDB_txn *txn;
0099     
0100     /* Unlink db firstly... */
0101     assert_equal(Bflddbunlink(), EXSUCCEED);
0102     
0103     /* Load DB... (open handles, etc...) */
0104     assert_equal(Bflddbload(), EXTRUE);
0105     
0106     /* add some fields now */
0107     get_tran(&txn);
0108 
0109     UBF_LOG(log_error, "About to ADD custom fields!!!");
0110     assert_equal(Bflddbadd(txn, BFLD_STRING, 3000, "T_HELLO_STR"), EXSUCCEED);
0111     assert_equal(Bflddbadd(txn, BFLD_SHORT, 3001, "T_HELLO_SHORT"), EXSUCCEED);
0112     assert_equal(Bflddbadd(txn, BFLD_CHAR, 3002, "T_HELLO_CHAR"), EXSUCCEED);
0113     assert_equal(Bflddbadd(txn, BFLD_LONG, 3003, "T_HELLO_LONG"), EXSUCCEED);
0114     
0115     assert_equal(edb_txn_commit(txn), EXSUCCEED);
0116 }
0117 
0118 /**
0119  * Call server. This assumes that custom tables are already loaded
0120  */
0121 Ensure(ubfdb_callsv)
0122 {
0123     UBFH *p_ub;
0124     long l;
0125     long rsplen;
0126     
0127     for (l=0; l<100; l++)
0128     {
0129         p_ub = (UBFH *)tpalloc("UBF", NULL, 56000);
0130         assert_not_equal(p_ub, NULL);
0131         assert_equal(CBchg(p_ub, Bfldid("T_HELLO_STR"), 0, "HELLO WORLD", 0L, BFLD_STRING), 
0132                 EXSUCCEED);
0133         assert_equal(CBchg(p_ub, Bfldid("T_HELLO_SHORT"), 0, "56", 0L, BFLD_STRING), 
0134                 EXSUCCEED);
0135         assert_equal(CBchg(p_ub, Bfldid("T_HELLO_CHAR"), 0, "A", 0L, BFLD_STRING),
0136                 EXSUCCEED);
0137         assert_equal(Bchg(p_ub, Bfldid("T_HELLO_LONG"), 0, (char *)&l, 0L),
0138                 EXSUCCEED);
0139         /* test standard field too */
0140         assert_equal(CBchg(p_ub, T_STRING_FLD, 0, "ABC", 0L, BFLD_STRING),
0141                 EXSUCCEED);
0142         
0143         assert_equal(tpcall("TESTSV", (char *)p_ub, 0L, (char **)&p_ub, &rsplen,0), 
0144                 EXSUCCEED);
0145         
0146         tpfree((char *)p_ub);
0147     }
0148 }
0149 
0150 /**
0151  * UBFDB testing suite
0152  * @return
0153  */
0154 TestSuite *ubfdb_ipc_tests() 
0155 {
0156     TestSuite *suite = create_test_suite();
0157     
0158     set_setup(suite, basic_setup);
0159     set_teardown(suite, basic_teardown);
0160 
0161     add_test(suite, ubfdb_setup);
0162     add_test(suite, ubfdb_callsv);
0163     
0164     return suite;
0165 }
0166 
0167 /*
0168  * Main test entry.
0169  */
0170 int main(int argc, char** argv)
0171 {
0172     TestSuite *suite = create_test_suite();
0173     int ret;
0174 
0175     add_suite(suite, ubfdb_ipc_tests());
0176     
0177     if (argc > 1)
0178     {
0179         ret=run_single_test(suite,argv[1],create_text_reporter());
0180     }
0181     else
0182     {
0183         ret=run_test_suite(suite, create_text_reporter());
0184     }
0185 
0186     destroy_test_suite(suite);
0187 
0188     return ret;
0189 }
0190 /* vim: set ts=4 sw=4 et smartindent: */