/[ascend]/trunk/ascend/utilities/test/test_mem.c
ViewVC logotype

Diff of /trunk/ascend/utilities/test/test_mem.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2526 by jpye, Thu Jan 19 21:36:01 2012 UTC revision 2527 by jpye, Fri Jan 20 00:44:37 2012 UTC
# Line 21  Line 21 
21   *  COPYING.   *  COPYING.
22   */   */
23    
24    /* FIXME this test needs to move to 'general'. */
25    
26  #include <stdio.h>  #include <stdio.h>
27  #include <ascend/general/platform.h>  #include <ascend/general/platform.h>
28  #include <ascend/general/ascMalloc.h>  #include <ascend/general/ascMalloc.h>
# Line 390  static void test_mem(void) Line 392  static void test_mem(void)
392    /* test mem_set_byte(), mem_get_byte() */    /* test mem_set_byte(), mem_get_byte() */
393    
394    memset(str1, '\0', STR_LEN);    memset(str1, '\0', STR_LEN);
395    CU_TEST('\0' == mem_get_byte((long)str1));    CU_TEST('\0' == mem_get_byte((asc_intptr_t)str1));
396    
397    mem_set_byte((long)str1, 0xff);    mem_set_byte((asc_intptr_t)str1, 0xff);
398    CU_TEST(0xff == mem_get_byte((long)str1));    CU_TEST(0xff == mem_get_byte((POINTER)str1));
399    
400    mem_set_byte((long)str1, '\t');    mem_set_byte((POINTER)str1, '\t');
401    CU_TEST('\t' == mem_get_byte((long)str1));    CU_TEST('\t' == mem_get_byte((POINTER)str1));
402    
403    mem_set_byte((long)str1, '\0');    mem_set_byte((POINTER)str1, '\0');
404    CU_TEST('\0' == mem_get_byte((long)str1));    CU_TEST('\0' == mem_get_byte((POINTER)str1));
405    
406    /* test mem_set_int(), mem_get_int() */    /* test mem_set_int(), mem_get_int() */
407    
408    memset(str1, '\0', STR_LEN);    memset(str1, '\0', STR_LEN);
409    CU_TEST(0 == mem_get_int((long)str1));    CU_TEST(0 == mem_get_int((POINTER)str1));
410    
411    mem_set_int((long)str1, 0xff72);    mem_set_int((POINTER)str1, 0xff72);
412    CU_TEST(0xff72 == mem_get_int((long)str1));    CU_TEST(0xff72 == mem_get_int((POINTER)str1));
413    
414    mem_set_int((long)str1, '\t');    mem_set_int((POINTER)str1, '\t');
415    CU_TEST('\t' == mem_get_int((long)str1));    CU_TEST('\t' == mem_get_int((POINTER)str1));
416    
417    mem_set_int((long)str1, 0);    mem_set_int((POINTER)str1, 0);
418    CU_TEST(0 == mem_get_int((long)str1));    CU_TEST(0 == mem_get_int((POINTER)str1));
419    
420    /* test mem_set_long(), mem_get_long() */    /* test mem_set_long(), mem_get_long() */
421    
422    memset(str1, '\0', STR_LEN);    memset(str1, '\0', STR_LEN);
423    CU_TEST(0 == mem_get_long((long)str1));    CU_TEST(0 == mem_get_long((POINTER)str1));
424    
425    mem_set_long((long)str1, 0xff72);    mem_set_long((POINTER)str1, 0xff72);
426    CU_TEST(0xff72 == mem_get_long((long)str1));    CU_TEST(0xff72 == mem_get_long((POINTER)str1));
427    
428    mem_set_long((long)str1, '\t');    mem_set_long((POINTER)str1, '\t');
429    CU_TEST('\t' == mem_get_long((long)str1));    CU_TEST('\t' == mem_get_long((POINTER)str1));
430    
431    mem_set_long((long)str1, 0);    mem_set_long((POINTER)str1, 0);
432    CU_TEST(0 == mem_get_long((long)str1));    CU_TEST(0 == mem_get_long((POINTER)str1));
433    
434    /* test mem_set_float(), mem_get_float() */    /* test mem_set_float(), mem_get_float() */
435    
436    memset(str1, '\0', STR_LEN);    memset(str1, '\0', STR_LEN);
437    CU_ASSERT_DOUBLE_EQUAL(0.0, mem_get_float((long)str1), 0.001);    CU_ASSERT_DOUBLE_EQUAL(0.0, mem_get_float((POINTER)str1), 0.001);
438    
439    mem_set_float((long)str1, 1.501436);    mem_set_float((POINTER)str1, 1.501436);
440    CU_ASSERT_DOUBLE_EQUAL(1.501436, mem_get_float((long)str1), 0.00001);    CU_ASSERT_DOUBLE_EQUAL(1.501436, mem_get_float((POINTER)str1), 0.00001);
441    
442    mem_set_float((long)str1, 9.3e-10);    mem_set_float((POINTER)str1, 9.3e-10);
443    CU_ASSERT_DOUBLE_EQUAL(9.3e-10, mem_get_float((long)str1), 0.001);    CU_ASSERT_DOUBLE_EQUAL(9.3e-10, mem_get_float((POINTER)str1), 0.001);
444    
445    mem_set_float((long)str1, 0.0);    mem_set_float((POINTER)str1, 0.0);
446    CU_ASSERT_DOUBLE_EQUAL(0.0, mem_get_float((long)str1), 0.001);    CU_ASSERT_DOUBLE_EQUAL(0.0, mem_get_float((POINTER)str1), 0.001);
447    
448    /* test mem_set_double(), mem_get_double() */    /* test mem_set_double(), mem_get_double() */
449    
450    memset(str1, '\0', STR_LEN);    memset(str1, '\0', STR_LEN);
451    CU_ASSERT_DOUBLE_EQUAL(0.0, mem_get_double((long)str1), 0.001);    CU_ASSERT_DOUBLE_EQUAL(0.0, mem_get_double((POINTER)str1), 0.001);
452    
453    mem_set_double((long)str1, 1.501436872625);    mem_set_double((POINTER)str1, 1.501436872625);
454    CU_ASSERT_DOUBLE_EQUAL(1.501436872625, mem_get_double((long)str1), 0.000000000001);    CU_ASSERT_DOUBLE_EQUAL(1.501436872625, mem_get_double((POINTER)str1), 0.000000000001);
455    
456    mem_set_double((long)str1, 9.32626e-154);    mem_set_double((POINTER)str1, 9.32626e-154);
457    CU_ASSERT_DOUBLE_EQUAL(9.32626e-154, mem_get_double((long)str1), 0.00001);    CU_ASSERT_DOUBLE_EQUAL(9.32626e-154, mem_get_double((POINTER)str1), 0.00001);
458    
459    mem_set_double((long)str1, 0.0);    mem_set_double((POINTER)str1, 0.0);
460    CU_ASSERT_DOUBLE_EQUAL(0.0, mem_get_double((long)str1), 0.001);    CU_ASSERT_DOUBLE_EQUAL(0.0, mem_get_double((POINTER)str1), 0.001);
461    
462    /* test mem_set_unsigned(), mem_get_unsigned() */    /* test mem_set_unsigned(), mem_get_unsigned() */
463    
464    memset(str1, '\0', STR_LEN);    memset(str1, '\0', STR_LEN);
465    CU_TEST(0 == mem_get_unsigned((long)str1));    CU_TEST(0 == mem_get_unsigned((POINTER)str1));
466    
467    mem_set_unsigned((long)str1, 0xff72);    mem_set_unsigned((POINTER)str1, 0xff72);
468    CU_TEST(0xff72 == mem_get_unsigned((long)str1));    CU_TEST(0xff72 == mem_get_unsigned((POINTER)str1));
469    
470    mem_set_unsigned((long)str1, '\t');    mem_set_unsigned((POINTER)str1, '\t');
471    CU_TEST('\t' == mem_get_unsigned((long)str1));    CU_TEST('\t' == mem_get_unsigned((POINTER)str1));
472    
473    mem_set_unsigned((long)str1, 0);    mem_set_unsigned((POINTER)str1, 0);
474    CU_TEST(0 == mem_get_unsigned((long)str1));    CU_TEST(0 == mem_get_unsigned((POINTER)str1));
475    
476    /* test mem_create_store(), mem_destroy_store() */    /* test mem_create_store(), mem_destroy_store() */
477    
478    ms = mem_create_store(0, 10, sizeof(int), 10, 10); /* create a store - length < 1 (error) */    ms = mem_create_store(0, 10, sizeof(int), 10, 10); /* create a store - length < 1 (error) */
479    CU_TEST(NULL == ms);    CU_TEST(NULL == ms);
480    if (NULL != ms)    if(NULL != ms)mem_destroy_store(ms);
     mem_destroy_store(ms);  
481    
482    ms = mem_create_store(10, 0, sizeof(int), 10, 10); /* create a store - width < 1 (error) */    ms = mem_create_store(10, 0, sizeof(int), 10, 10); /* create a store - width < 1 (error) */
483    CU_TEST(NULL == ms);    CU_TEST(NULL == ms);
484    if (NULL != ms)    if(NULL != ms)mem_destroy_store(ms);
     mem_destroy_store(ms);  
485    
486    ms = mem_create_store(10, 10, 0, 10, 10);          /* create a store - eltsze < 1 (ok) */    ms = mem_create_store(10, 10, 0, 10, 10);          /* create a store - eltsze < 1 (ok) */
487    CU_TEST(NULL != ms);    CU_TEST(NULL != ms);
# Line 494  static void test_mem(void) Line 494  static void test_mem(void)
494    CU_TEST(10 == stats.str_len);    CU_TEST(10 == stats.str_len);
495    CU_TEST(10 == stats.str_wid);    CU_TEST(10 == stats.str_wid);
496    
497    if (NULL != ms)    if(NULL != ms)mem_destroy_store(ms);
     mem_destroy_store(ms);  
498    
499    ms = mem_create_store(10, 10, sizeof(int), 10, 10);/* create a store for ints */    ms = mem_create_store(10, 10, sizeof(int), 10, 10);/* create a store for ints */
500    CU_TEST(NULL != ms);    CU_TEST(NULL != ms);

Legend:
Removed from v.2526  
changed lines
  Added in v.2527

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22