/[ascend]/trunk/ascend/compiler/test/test_notes.c
ViewVC logotype

Diff of /trunk/ascend/compiler/test/test_notes.c

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

revision 3396 by jpye, Mon Jun 11 10:09:29 2018 UTC revision 3397 by jpye, Tue Jun 12 04:34:02 2018 UTC
# Line 42  Line 42 
42  #include <test/common.h>  #include <test/common.h>
43  #include <test/assertimpl.h>  #include <test/assertimpl.h>
44    
45  #define NOTES_DEBUG  //#define NOTES_DEBUG
46  #ifdef NOTES_DEBUG  #ifdef NOTES_DEBUG
47  # define MSG CONSOLE_DEBUG  # define MSG CONSOLE_DEBUG
48  #else  #else
# Line 81  static const char *model_test2 = "\n\ Line 81  static const char *model_test2 = "\n\
81          NOTES\n\          NOTES\n\
82              'author' SELF {notesauthor}\n\              'author' SELF {notesauthor}\n\
83              'description' y {variable called 'y'}\n\              'description' y {variable called 'y'}\n\
84              'description' a['left'] {the left one}\n\              'description' x {variable called 'x'}\n\
85                'description' a['left'] {the left one} (*this note won't parse*)\n\
86          END NOTES;\n\          END NOTES;\n\
87          x \"hello\" IS_A real;\n\          x \"hello\" IS_A real;\n\
88          rel1: x - 1 = 0;\n\          rel1: x - 1 = 0;\n\
# Line 121  static void test_test2(void){ Line 122  static void test_test2(void){
122      CU_ASSERT(FindType(AddSymbol("test1"))!=NULL);      CU_ASSERT(FindType(AddSymbol("test1"))!=NULL);
123    
124      l = GetNotes(LibraryNote(),NOTESWILD,NOTESWILD,NOTESWILD,NOTESWILD,nd_wild);      l = GetNotes(LibraryNote(),NOTESWILD,NOTESWILD,NOTESWILD,NOTESWILD,nd_wild);
125      CU_ASSERT(gl_length(l)==4);      CU_ASSERT(gl_length(l)==5);
126      int i;      int i;
127      for(i=1;i<=gl_length(l);++i){      for(i=1;i<=gl_length(l);++i){
128          struct Note *N = gl_fetch(l,i);          struct Note *N = gl_fetch(l,i);
# Line 138  static void test_test2(void){ Line 139  static void test_test2(void){
139      }      }
140      gl_destroy(l);      gl_destroy(l);
141    
142      // GetNotes(dbid,typename,language,id,NULL,nd_empty);      // GetNotes(dbid,typename,language,id,method,notedata);
143      l = GetNotes(LibraryNote(),AddSymbol("test1"),AddSymbol("inline"),AddSymbol("x"),NOTESWILD,nd_wild);      l = GetNotes(LibraryNote(),AddSymbol("test1"),AddSymbol("inline"),AddSymbol("x"),NOTESWILD,nd_wild);
144      CU_ASSERT(gl_length(l)==1);      CU_ASSERT(gl_length(l)==1);
145      CU_ASSERT(0==strcmp(BCS(GetNoteText(gl_fetch(l,1))),"hello"));      CU_ASSERT(0==strcmp(BCS(GetNoteText(gl_fetch(l,1))),"hello"));
146      CU_ASSERT(AddSymbol("inline")==GetNoteLanguage(gl_fetch(l,1)));      CU_ASSERT(AddSymbol("inline")==GetNoteLanguage(gl_fetch(l,1)));
147      CU_ASSERT(0==strcmp("mystr_global_1<0>",GetNoteFilename(gl_fetch(l,1))));      CU_ASSERT(0==strcmp("mystr_global_1<0>",GetNoteFilename(gl_fetch(l,1))));
148      CU_ASSERT(14==GetNoteLineNum(gl_fetch(l,1)));      CU_ASSERT(15==GetNoteLineNum(gl_fetch(l,1)));
149      CU_ASSERT(NULL==GetNoteMethod(gl_fetch(l,1)));      CU_ASSERT(NULL==GetNoteMethod(gl_fetch(l,1)));
150      CU_ASSERT(AddSymbol("test1")==GetNoteType(gl_fetch(l,1)));      CU_ASSERT(AddSymbol("test1")==GetNoteType(gl_fetch(l,1)));
151      gl_destroy(l);      gl_destroy(l);
152    
153        // HoldNoteData, HeldNotes, ReleaseNoteData
154        void *h1, *h2;
155        // clear all held notes
156        ReleaseNoteData(LibraryNote(),(void*)0x1);
157        // TODO attempt to store a bogus list
158        l2 = gl_create(10);
159        char *xx = "nothing";
160        gl_append_ptr(l2,xx);
161        h1 = HoldNoteData(LibraryNote(),l2);
162        CU_ASSERT(h1 == NULL);
163        gl_destroy(l2);
164        // store some real notes
165        l = GetNotes(LibraryNote(),NOTESWILD,AddSymbol("inline"),NOTESWILD,NOTESWILD,nd_wild);
166        CU_ASSERT(gl_length(l)==2);
167        h1 = HoldNoteData(LibraryNote(),l);
168        CU_ASSERT(h1 != NULL);
169        // retreive stored notes, check they are as expected
170        l2 = HeldNotes(LibraryNote(),h1);
171        CU_ASSERT(l2 != NULL);
172        CU_ASSERT(l == l2);
173        CU_ASSERT(0==strcmp(BCS(GetNoteText(gl_fetch(l2,1))),"yoohoo"));
174        CU_ASSERT(0==strcmp(BCS(GetNoteText(gl_fetch(l2,2))),"hello"));
175        CU_ASSERT(2==gl_length(l2));
176        ReleaseNoteData(LibraryNote(),h1);
177        //gl_destroy(l);
178    
179        // release all held lists (shouldn't be any others there anyway
180        ReleaseNoteData(LibraryNote(),(void *)0x1);
181    
182        l = GetNotes(LibraryNote(),NOTESWILD,AddSymbol("author"),NOTESWILD,NOTESWILD,nd_wild);
183        CU_ASSERT(gl_length(l)==1);
184        h1 = HoldNoteData(LibraryNote(),l);
185        CU_ASSERT(h1 !=NULL);
186    
187        l2 = GetNotes(LibraryNote(),NOTESWILD,AddSymbol("description"),NOTESWILD,NOTESWILD,nd_wild);
188        CU_ASSERT(gl_length(l2)==2);
189        h2 = HoldNoteData(LibraryNote(),l2);
190        CU_ASSERT(h2 !=NULL);
191    
192        // release all held lists (shouldn't be any others there anyway
193        ReleaseNoteData(LibraryNote(),(void *)0x1);
194    
195      DestroyNotesOnType(LibraryNote(),AddSymbol("test1"));      DestroyNotesOnType(LibraryNote(),AddSymbol("test1"));
196      l = GetNotes(LibraryNote(),NOTESWILD,NOTESWILD,NOTESWILD,NOTESWILD,nd_wild);      l = GetNotes(LibraryNote(),NOTESWILD,NOTESWILD,NOTESWILD,NOTESWILD,nd_wild);
197      CU_ASSERT(gl_length(l)==1);      CU_ASSERT(gl_length(l)==1);

Legend:
Removed from v.3396  
changed lines
  Added in v.3397

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