Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:49:17

0001 /**
0002 sframe_test.cc
0003 ===============
0004 
0005 ::
0006 
0007    ~/o/sysrap/tests/sframe_test.sh
0008 
0009 **/
0010 
0011 
0012 #include "sframe.h"
0013 
0014 void test_really_uninitialized_dtor()
0015 {
0016     sframe fr ; 
0017 }
0018 
0019 
0020 void test_dtor_after_copy_for_double_free()
0021 {
0022     sframe a ; 
0023     a.setTranslate(100.f, 200.f, 300.f) ; 
0024     a.prepare(); 
0025 
0026     sframe b = a ; 
0027 
0028     /**
0029     BEFORE ADDING COPY CTOR THAT RUNS prepare 
0030 
0031     assert( b.tr_m2w == a.tr_m2w ); 
0032     assert( b.tr_w2m == a.tr_w2m ); 
0033     //here is the cause of double free : b thinks it owns the pointers of a 
0034     **/
0035 
0036     // AFTER ADDING COPY CTOR THAT RUNS prepar
0037 
0038     assert( b.tr_m2w != a.tr_m2w ); 
0039     assert( b.tr_w2m != a.tr_w2m ); 
0040 
0041 }
0042 
0043 
0044 
0045 void test_uninitialized()
0046 {
0047     sframe fr = {} ; 
0048     std::cout << "fr" << std::endl << fr << std::endl ; 
0049 
0050     std::cout << "fr.m2w.q3.i.w " << fr.m2w.q3.i.w  << std::endl; 
0051     std::cout << "fr.m2w.q3.f.w " << fr.m2w.q3.f.w  << std::endl; 
0052 }
0053 
0054 
0055 void test_save_load()
0056 {
0057     sframe a ; 
0058     a.frs = "a test of persisting via metadata" ;
0059     a.ce.x = 1.f ; 
0060     a.ce.y = 2.f ; 
0061     a.ce.z = 3.f ; 
0062     a.ce.w = 4.f ; 
0063     std::cout << "a" << std::endl << a << std::endl ; 
0064     a.save("$FOLD"); 
0065 
0066     sframe b = sframe::Load("$FOLD");  
0067     std::cout << "b" << std::endl << b << std::endl ; 
0068     assert( strcmp(a.frs, b.frs) == 0 ); 
0069 }
0070 
0071 void test_load()
0072 {
0073     sframe b = sframe::Load("$FOLD");  
0074     std::cout << "b" << std::endl << b << std::endl ; 
0075 }
0076 
0077 void test_setTranslate()
0078 {
0079     sframe fr ; 
0080     fr.setTranslate(100.f, 200.f, 300.f) ; 
0081     fr.prepare(); 
0082 
0083     std::cout << fr << std::endl ; 
0084     fr.save("$FOLD"); 
0085 }
0086 
0087 
0088 int main(int argc, char** argv)
0089 {
0090     //test_really_uninitialized_dtor(); 
0091     test_dtor_after_copy_for_double_free(); 
0092 
0093     /*
0094     test_uninitialized(); 
0095     test_save_load() ; 
0096     test_load(); 
0097     test_setTranslate(); 
0098     */
0099 
0100     return 0 ; 
0101 }