ut_tuple.c
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00022 #include "CuTest.h"
00023 #include "pm.h"
00024
00025
00031 void
00032 ut_tuple_new_000(CuTest *tc)
00033 {
00034 pPmObj_t ptuple;
00035 PmReturn_t retval;
00036
00037 pm_init(MEMSPACE_RAM, C_NULL);
00038
00039
00040 retval = tuple_new(0, &ptuple);
00041 CuAssertTrue(tc, retval == PM_RET_OK);
00042 CuAssertTrue(tc, ((pPmTuple_t)ptuple)->length == 0);
00043
00044
00045 retval = tuple_new(1, &ptuple);
00046 CuAssertTrue(tc, retval == PM_RET_OK);
00047 CuAssertTrue(tc, ((pPmTuple_t)ptuple)->length == 1);
00048
00049 }
00050
00051
00057 void
00058 ut_tuple_copy_000(CuTest *tc)
00059 {
00060 pPmObj_t ptuple;
00061 pPmObj_t ptuplecopy;
00062 pPmObj_t pobj0;
00063 pPmObj_t pobj1;
00064 pPmObj_t pobj2;
00065 PmReturn_t retval;
00066
00067 pm_init(MEMSPACE_RAM, C_NULL);
00068
00069 retval = tuple_new(3, &ptuple);
00070 retval = dict_new(&pobj0);
00071 retval = list_new(&pobj1);
00072 retval = int_new(42, &pobj2);
00073 ((pPmTuple_t)ptuple)->val[0] = pobj0;
00074 ((pPmTuple_t)ptuple)->val[1] = pobj1;
00075 ((pPmTuple_t)ptuple)->val[2] = pobj2;
00076
00077
00078 retval = tuple_copy(ptuple, &ptuplecopy);
00079 CuAssertTrue(tc, retval == PM_RET_OK);
00080 CuAssertTrue(tc, obj_compare(ptuple, ptuplecopy) == C_SAME);
00081 }
00082
00083
00089 void
00090 ut_tuple_getItem_000(CuTest *tc)
00091 {
00092 pPmObj_t ptuple;
00093 pPmObj_t pobj0;
00094 pPmObj_t pobj1;
00095 pPmObj_t pobj2;
00096 pPmObj_t pget;
00097 PmReturn_t retval;
00098
00099 pm_init(MEMSPACE_RAM, C_NULL);
00100
00101 retval = tuple_new(3, &ptuple);
00102 retval = dict_new(&pobj0);
00103 retval = list_new(&pobj1);
00104 retval = int_new(42, &pobj2);
00105 ((pPmTuple_t)ptuple)->val[0] = pobj0;
00106 ((pPmTuple_t)ptuple)->val[1] = pobj1;
00107 ((pPmTuple_t)ptuple)->val[2] = pobj2;
00108
00109
00110 retval = tuple_getItem(ptuple, 0, &pget);
00111 CuAssertTrue(tc, retval == PM_RET_OK);
00112 CuAssertTrue(tc, pget == pobj0);
00113 retval = tuple_getItem(ptuple, 1, &pget);
00114 CuAssertTrue(tc, retval == PM_RET_OK);
00115 CuAssertTrue(tc, pget == pobj1);
00116 retval = tuple_getItem(ptuple, 2, &pget);
00117 CuAssertTrue(tc, retval == PM_RET_OK);
00118 CuAssertTrue(tc, pget == pobj2);
00119 }
00120
00121
00123 CuSuite *getSuite_testTupleObj(void)
00124 {
00125 CuSuite* suite = CuSuiteNew();
00126
00127 SUITE_ADD_TEST(suite, ut_tuple_new_000);
00128 SUITE_ADD_TEST(suite, ut_tuple_copy_000);
00129 SUITE_ADD_TEST(suite, ut_tuple_getItem_000);
00130
00131 return suite;
00132 }