PageRenderTime 18ms CodeModel.GetById 12ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 1ms

/npk/cli/tests/npk_06_sync_03.cpp

http://npk.googlecode.com/
C++ | 62 lines | 43 code | 19 blank | 0 comment | 7 complexity | 53b9d03f83aee8fc7abb604029080a99 MD5 | raw file
 1#include "testutil.h"
 2#include <npk.h>
 3
 4int npk_06_sync_03( int argc, char * argv [] )
 5{
 6    CMD( "../npk test.npk -create -add sample.txt@remain.txt sample.txt@update.txt sample.txt@notupdate.tmp sample.txt@notdelete.tmp --f --k 1:2:3:4" );
 7    CMD( "mkdir sync_test_03" );
 8    CP( "sample.txt", "sync_test_03/add.txt" );
 9    CP( "sample.txt", "sync_test_03/notadd.tmp" );
10    CP( "sample.txt", "sync_test_03/remain.txt" );
11    CP( "sample2.txt", "sync_test_03/update.txt" );
12    CP( "sample2.txt", "sync_test_03/notupdate.tmp" );
13
14    CMD( "../npk test.npk -sync sync_test_03 --sa --sd --ig *.tmp --k 1:2:3:4" );
15
16    int teakey[4] = {1,2,3,4};
17    NPK_PACKAGE pack = npk_package_open( "test.npk", teakey );
18
19    CHECK( pack != NULL );
20
21    NPK_ENTITY entity;
22    NPK_SIZE size;
23    void* buf;
24
25    entity = npk_package_get_entity( pack, "remain.txt" );
26    CHECK( entity != NULL );
27
28    entity = npk_package_get_entity( pack, "add.txt" );
29    CHECK( entity != NULL );
30
31    entity = npk_package_get_entity( pack, "notadd.tmp" );
32    CHECK( entity == NULL );
33
34    entity = npk_package_get_entity( pack, "notdelete.tmp" );
35    CHECK( entity != NULL );
36
37    entity = npk_package_get_entity( pack, "update.txt" );
38    CHECK( entity != NULL );
39
40    size = npk_entity_get_size( entity );
41    buf = malloc( size );
42
43    CHECK( npk_entity_read( entity, buf ) );
44    CHECK_EQUAL_STR_WITH_FILE( (const char*)buf, "sample2.txt" );
45
46    free( buf );
47
48    entity = npk_package_get_entity( pack, "notupdate.tmp" );
49    CHECK( entity != NULL );
50
51    size = npk_entity_get_size( entity );
52    buf = malloc( size );
53
54    CHECK( npk_entity_read( entity, buf ) );
55    CHECK_EQUAL_STR_WITH_FILE( (const char*)buf, "sample.txt" );
56
57    free( buf );
58
59    npk_package_close( pack );
60
61    return 0;
62}