Imported Debian version 1.0~trusty
[deb_vid.stab.git] / tests / test_store_restore.c
1 int compare_localmotions(const LocalMotions* lms1, const LocalMotions* lms2){
2 test_bool(vs_vector_size(lms1) == vs_vector_size(lms2));
3 int i;
4 for(i=0; i<vs_vector_size(lms1); i++){
5 test_bool(LMGet(lms1,i)->v.x == LMGet(lms2,i)->v.x);
6 test_bool(LMGet(lms1,i)->v.y == LMGet(lms2,i)->v.y);
7 }
8 return 1;
9 }
10
11 int test_store_restore(TestData* testdata){
12 VSMotionDetectConfig mdconf = vsMotionDetectGetDefaultConfig("test_motionDetect");
13 VSMotionDetect md;
14 test_bool(vsMotionDetectInit(&md, &mdconf, &testdata->fi) == VS_OK);
15
16 LocalMotions lms;
17 int i;
18 for(i=0; i<2; i++){
19 test_bool(vsMotionDetection(&md, &lms,&testdata->frames[i])== VS_OK);
20 if (i==0) vs_vector_del(&lms);
21 }
22
23 FILE* f = fopen("lmtest","w");
24 vsStoreLocalmotions(f,&lms);
25 fclose(f);
26 f = fopen("lmtest","r");
27 LocalMotions test = vsRestoreLocalmotions(f);
28 fclose(f);
29 vsStoreLocalmotions(stderr,&test);
30 compare_localmotions(&lms,&test);
31 fprintf(stderr,"\n** LM and LMS OKAY\n");
32
33 f = fopen("lmstest","w");
34 md.frameNum=1;
35 vsPrepareFile(&md,f);
36 vsWriteToFile(&md,f,&lms);
37 md.frameNum=2;
38 vsWriteToFile(&md,f,&test);
39 fclose(f);
40
41 f = fopen("lmstest","r");
42 test_bool(vsReadFileVersion(f)==1);
43 LocalMotions read1;
44 test_bool(vsReadFromFile(f,&read1)==1);
45 compare_localmotions(&lms,&read1);
46 LocalMotions read2;
47 test_bool(vsReadFromFile(f,&read2)==2);
48 compare_localmotions(&test,&read2);
49 fclose(f);
50 fprintf(stderr,"** Reading file stepwise OKAY\n");
51 vs_vector_del(&read1);
52 vs_vector_del(&read2);
53 vs_vector_del(&test);
54 vs_vector_del(&lms);
55
56 f = fopen("lmstest","r");
57 VSManyLocalMotions mlms;
58 test_bool(vsReadLocalMotionsFile(f,&mlms)==VS_OK);
59 test_bool(vs_vector_size(&mlms)==2);
60 fprintf(stderr,"** Entire file routine OKAY\n\n");
61
62 for(i=0; i< vs_vector_size(&mlms); i++){
63 if(VSMLMGet(&mlms,i))
64 vs_vector_del(VSMLMGet(&mlms,i));
65 }
66 vs_vector_del(&mlms);
67
68 return 1;
69 }