ut_int.c

00001 /*
00002 # This file is Copyright 2003, 2006, 2007, 2009 Dean Hall.
00003 #
00004 # This file is part of the Python-on-a-Chip program.
00005 # Python-on-a-Chip is free software: you can redistribute it and/or modify
00006 # it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1.
00007 #
00008 # Python-on-a-Chip is distributed in the hope that it will be useful,
00009 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00011 # A copy of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1
00012 # is seen in the file COPYING up one directory from this.
00013 */
00014 
00015 
00022 #include "CuTest.h"
00023 #include "pm.h"
00024 
00025 
00026 /* BEGIN unit tests ported from Snarf */
00033 void
00034 ut_int_new_000(CuTest *tc)
00035 {
00036     PmReturn_t retval;
00037     pPmObj_t pint;
00038 
00039     pm_init(MEMSPACE_RAM, C_NULL);
00040     retval = int_new(42, &pint);
00041     
00042     /* Check the return value of the load function */
00043     CuAssertTrue(tc, retval == PM_RET_OK);
00044     
00045     /* Check that the type is INT */
00046     CuAssertTrue(tc, OBJ_GET_TYPE(pint) == OBJ_TYPE_INT);
00047     
00048     /* Check that the value is 42 */
00049     CuAssertTrue(tc, ((pPmInt_t)pint)->val == 42);
00050 }
00051 /* END unit tests ported from Snarf */
00052 
00053 
00061 void
00062 ut_int_dup_000(CuTest *tc)
00063 {
00064     PmReturn_t retval;
00065     pPmObj_t pint;
00066     pPmObj_t pdup;
00067 
00068     pm_init(MEMSPACE_RAM, C_NULL);
00069     retval = int_new(42, &pint);
00070     retval = int_dup(pint, &pdup);
00071     
00072     /* Check the return value of the load function */
00073     CuAssertTrue(tc, retval == PM_RET_OK);
00074     
00075     /* Check that the type is INT */
00076     CuAssertTrue(tc, OBJ_GET_TYPE(pdup) == OBJ_TYPE_INT);
00077     
00078     /* Check that the value is 42 */
00079     CuAssertTrue(tc, ((pPmInt_t)pdup)->val == 42);
00080     
00081     /* Check that comparing the two objects yields true */
00082     CuAssertTrue(tc, obj_compare(pint, pdup) == C_SAME);
00083 }
00084 
00085 
00093 void
00094 ut_int_positive_000(CuTest *tc)
00095 {
00096     PmReturn_t retval;
00097     pPmObj_t pint;
00098     pPmObj_t ppos;
00099 
00100     pm_init(MEMSPACE_RAM, C_NULL);
00101     retval = int_new(42, &pint);
00102     retval = int_positive(pint, &ppos);
00103     
00104     /* Check the return value of the load function */
00105     CuAssertTrue(tc, retval == PM_RET_OK);
00106     
00107     /* Check that the type is INT */
00108     CuAssertTrue(tc, OBJ_GET_TYPE(ppos) == OBJ_TYPE_INT);
00109     
00110     /* Check that the value is 42 */
00111     CuAssertTrue(tc, ((pPmInt_t)ppos)->val == 42);
00112     
00113     /* Check that comparing the two objects yields true */
00114     CuAssertTrue(tc, obj_compare(pint, ppos) == C_SAME);
00115 }
00116 
00117 
00125 void
00126 ut_int_positive_001(CuTest *tc)
00127 {
00128     PmReturn_t retval;
00129     pPmObj_t pint;
00130     pPmObj_t ppos;
00131 
00132     pm_init(MEMSPACE_RAM, C_NULL);
00133     retval = int_new(-42, &pint);
00134     retval = int_positive(pint, &ppos);
00135     
00136     /* Check the return value of the load function */
00137     CuAssertTrue(tc, retval == PM_RET_OK);
00138     
00139     /* Check that the type is INT */
00140     CuAssertTrue(tc, OBJ_GET_TYPE(ppos) == OBJ_TYPE_INT);
00141     
00142     /* Check that the value is 42 */
00143     CuAssertTrue(tc, ((pPmInt_t)ppos)->val == -42);
00144     
00145     /* Check that comparing the two objects yields true */
00146     CuAssertTrue(tc, obj_compare(pint, ppos) == C_SAME);
00147 }
00148 
00149 
00157 void
00158 ut_int_positive_002(CuTest *tc)
00159 {
00160     PmReturn_t retval;
00161     pPmObj_t pint;
00162     pPmObj_t ppos;
00163 
00164     pm_init(MEMSPACE_RAM, C_NULL);
00165     retval = int_new(0, &pint);
00166     retval = int_positive(pint, &ppos);
00167     
00168     /* Check the return value of the load function */
00169     CuAssertTrue(tc, retval == PM_RET_OK);
00170     
00171     /* Check that the type is INT */
00172     CuAssertTrue(tc, OBJ_GET_TYPE(ppos) == OBJ_TYPE_INT);
00173     
00174     /* Check that the value is 42 */
00175     CuAssertTrue(tc, ((pPmInt_t)ppos)->val == 0);
00176     
00177     /* Check that comparing the two objects yields true */
00178     CuAssertTrue(tc, obj_compare(pint, ppos) == C_SAME);
00179 }
00180 
00181 
00189 void
00190 ut_int_negative_000(CuTest *tc)
00191 {
00192     PmReturn_t retval;
00193     pPmObj_t pint;
00194     pPmObj_t pneg;
00195 
00196     pm_init(MEMSPACE_RAM, C_NULL);
00197     retval = int_new(42, &pint);
00198     retval = int_negative(pint, &pneg);
00199     
00200     /* Check the return value of the load function */
00201     CuAssertTrue(tc, retval == PM_RET_OK);
00202     
00203     /* Check that the type is INT */
00204     CuAssertTrue(tc, OBJ_GET_TYPE(pneg) == OBJ_TYPE_INT);
00205     
00206     /* Check that the value is 42 */
00207     CuAssertTrue(tc, ((pPmInt_t)pneg)->val == -42);
00208     
00209     /* Check that comparing the two objects yields false */
00210     CuAssertTrue(tc, obj_compare(pint, pneg) == C_DIFFER);
00211 }
00212 
00213 
00221 void
00222 ut_int_negative_001(CuTest *tc)
00223 {
00224     PmReturn_t retval;
00225     pPmObj_t pint;
00226     pPmObj_t pneg;
00227 
00228     pm_init(MEMSPACE_RAM, C_NULL);
00229     retval = int_new(-42, &pint);
00230     retval = int_negative(pint, &pneg);
00231     
00232     /* Check the return value of the load function */
00233     CuAssertTrue(tc, retval == PM_RET_OK);
00234     
00235     /* Check that the type is INT */
00236     CuAssertTrue(tc, OBJ_GET_TYPE(pneg) == OBJ_TYPE_INT);
00237     
00238     /* Check that the value is 42 */
00239     CuAssertTrue(tc, ((pPmInt_t)pneg)->val == 42);
00240     
00241     /* Check that comparing the two objects yields false */
00242     CuAssertTrue(tc, obj_compare(pint, pneg) == C_DIFFER);
00243 }
00244 
00245 
00253 void
00254 ut_int_negative_002(CuTest *tc)
00255 {
00256     PmReturn_t retval;
00257     pPmObj_t pint;
00258     pPmObj_t pneg;
00259 
00260     pm_init(MEMSPACE_RAM, C_NULL);
00261     retval = int_new(0, &pint);
00262     retval = int_negative(pint, &pneg);
00263     
00264     /* Check the return value of the load function */
00265     CuAssertTrue(tc, retval == PM_RET_OK);
00266     
00267     /* Check that the type is INT */
00268     CuAssertTrue(tc, OBJ_GET_TYPE(pneg) == OBJ_TYPE_INT);
00269     
00270     /* Check that the value is 0 */
00271     CuAssertTrue(tc, ((pPmInt_t)pneg)->val == 0);
00272     
00273     /* Check that comparing the two objects yields true */
00274     CuAssertTrue(tc, obj_compare(pint, pneg) == C_SAME);
00275 }
00276 
00277 
00285 void
00286 ut_int_bitInvert_000(CuTest *tc)
00287 {
00288     PmReturn_t retval;
00289     pPmObj_t pint;
00290     pPmObj_t pinv;
00291 
00292     pm_init(MEMSPACE_RAM, C_NULL);
00293     retval = int_new(42, &pint);
00294     retval = int_bitInvert(pint, &pinv);
00295     
00296     /* Check the return value of the load function */
00297     CuAssertTrue(tc, retval == PM_RET_OK);
00298     
00299     /* Check that the type is INT */
00300     CuAssertTrue(tc, OBJ_GET_TYPE(pinv) == OBJ_TYPE_INT);
00301     
00302     /* Check that the value is -43 */
00303     CuAssertTrue(tc, ((pPmInt_t)pinv)->val == -43);
00304     
00305     /* Check that comparing the two objects yields false */
00306     CuAssertTrue(tc, obj_compare(pint, pinv) == C_DIFFER);
00307 }
00308 /* BEGIN unit tests ported from Snarf */
00309 
00310 
00312 CuSuite *getSuite_testIntObj(void)
00313 {
00314     CuSuite* suite = CuSuiteNew();
00315 
00316     SUITE_ADD_TEST(suite, ut_int_new_000);
00317     SUITE_ADD_TEST(suite, ut_int_dup_000);
00318     SUITE_ADD_TEST(suite, ut_int_positive_000);
00319     SUITE_ADD_TEST(suite, ut_int_positive_001);
00320     SUITE_ADD_TEST(suite, ut_int_positive_002);
00321     SUITE_ADD_TEST(suite, ut_int_negative_000);
00322     SUITE_ADD_TEST(suite, ut_int_negative_001);
00323     SUITE_ADD_TEST(suite, ut_int_negative_002);
00324     SUITE_ADD_TEST(suite, ut_int_bitInvert_000);
00325 
00326     return suite;
00327 }

Generated on Mon Oct 18 07:40:47 2010 for Python-on-a-chip by  doxygen 1.5.9