Back to home page

Enduro/X

 
 

    


0001 /* 
0002 **
0003 ** @file test_readwrite.c
0004 ** 
0005 ** -----------------------------------------------------------------------------
0006 ** Enduro/X Middleware Platform for Distributed Transaction Processing
0007 ** Copyright (C) 2015, Mavimax, Ltd. All Rights Reserved.
0008 ** This software is released under one of the following licenses:
0009 ** GPL or Mavimax's license for commercial use.
0010 ** -----------------------------------------------------------------------------
0011 ** GPL license:
0012 ** 
0013 ** This program is free software; you can redistribute it and/or modify it under
0014 ** the terms of the GNU General Public License as published by the Free Software
0015 ** Foundation; either version 2 of the License, or (at your option) any later
0016 ** version.
0017 **
0018 ** This program is distributed in the hope that it will be useful, but WITHOUT ANY
0019 ** WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0020 ** PARTICULAR PURPOSE. See the GNU General Public License for more details.
0021 **
0022 ** You should have received a copy of the GNU General Public License along with
0023 ** this program; if not, write to the Free Software Foundation, Inc., 59 Temple
0024 ** Place, Suite 330, Boston, MA 02111-1307 USA
0025 **
0026 ** -----------------------------------------------------------------------------
0027 ** A commercial use license is available from Mavimax, Ltd
0028 ** contact@mavimax.com
0029 ** -----------------------------------------------------------------------------
0030 */
0031 
0032 #include <stdio.h>
0033 #include <stdlib.h>
0034 #include <cgreen/cgreen.h>
0035 #include <ubf.h>
0036 #include <ndrstandard.h>
0037 #include <string.h>
0038 #include "test.fd.h"
0039 #include "ubfunit1.h"
0040 
0041 
0042 /**
0043  * Test - Test buffer read/write
0044  */
0045 Ensure(test_readwrite)
0046 {
0047     char fb[1024];
0048     UBFH *p_ub = (UBFH *)fb;
0049     char fb2[1024];
0050     UBFH *p_ub2 = (UBFH *)fb2;
0051     assert_equal(Binit(p_ub, sizeof(fb)), EXSUCCEED);
0052     assert_equal(Binit(p_ub2, sizeof(fb2)), EXSUCCEED);
0053 
0054     /* Load test stuff */
0055     set_up_dummy_data(p_ub);
0056     open_test_temp("wb");
0057 
0058     assert_equal(Bwrite(p_ub, M_test_temp_file), EXSUCCEED);
0059     close_test_temp();
0060 
0061     /* Now read the stuff in second buffer */
0062     open_test_temp_for_read("rb");
0063     assert_equal(Bread(p_ub2, M_test_temp_file), EXSUCCEED);
0064 
0065     close_test_temp();
0066     remove_test_temp();
0067 
0068     /* Now compare the buffers */
0069     assert_equal(memcmp(p_ub, p_ub2, Bused(p_ub)), 0);
0070     /* run check on data */
0071     do_dummy_data_test(p_ub2);
0072 }
0073 
0074 /**
0075  * Dest buffer from read too short
0076  */
0077 Ensure(test_readwrite_err_space)
0078 {
0079     char fb[1024];
0080     UBFH *p_ub = (UBFH *)fb;
0081     char fb2[128];
0082     UBFH *p_ub2 = (UBFH *)fb2;
0083     assert_equal(Binit(p_ub, sizeof(fb)), EXSUCCEED);
0084     assert_equal(Binit(p_ub2, sizeof(fb2)), EXSUCCEED);
0085 
0086     /* Load test stuff */
0087     set_up_dummy_data(p_ub);
0088     open_test_temp("wb");
0089 
0090     assert_equal(Bwrite(p_ub, M_test_temp_file), EXSUCCEED);
0091     close_test_temp();
0092 
0093     /* Now read the stuff in second buffer */
0094     open_test_temp_for_read("rb");
0095     assert_equal(Bread(p_ub2, M_test_temp_file), EXFAIL);
0096     assert_equal(Berror, BNOSPACE);
0097 
0098     close_test_temp();
0099     remove_test_temp();
0100 }
0101 
0102 /**
0103  * Test unix error on bad file descriptor
0104  */
0105 Ensure(test_readwrite_invalid_descr)
0106 {
0107     char fb[1024];
0108     UBFH *p_ub = (UBFH *)fb;
0109     char fb2[128];
0110     UBFH *p_ub2 = (UBFH *)fb2;
0111     assert_equal(Binit(p_ub, sizeof(fb)), EXSUCCEED);
0112     assert_equal(Binit(p_ub2, sizeof(fb2)), EXSUCCEED);
0113 
0114     /* Load test stuff */
0115     set_up_dummy_data(p_ub);
0116     open_test_temp("r");
0117 
0118     assert_equal(Bwrite(p_ub, M_test_temp_file), EXFAIL);
0119     assert_equal(Berror, BEUNIX);
0120     close_test_temp();
0121 
0122     /* Now read the stuff in second buffer */
0123     open_test_temp_for_read("w");
0124     assert_equal(Bread(p_ub2, M_test_temp_file), EXFAIL);
0125     assert_equal(Berror, BEUNIX);
0126 
0127     close_test_temp();
0128     remove_test_temp();
0129 }
0130 
0131 TestSuite *ubf_readwrite_tests(void)
0132 {
0133     TestSuite *suite = create_test_suite();
0134 
0135     add_test(suite, test_readwrite);
0136     add_test(suite, test_readwrite_err_space);
0137     add_test(suite, test_readwrite_invalid_descr);
0138 
0139     return suite;
0140 }
0141