/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. int npk_06_sync_03( int argc, char * argv [] )
  4. {
  5. 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" );
  6. CMD( "mkdir sync_test_03" );
  7. CP( "sample.txt", "sync_test_03/add.txt" );
  8. CP( "sample.txt", "sync_test_03/notadd.tmp" );
  9. CP( "sample.txt", "sync_test_03/remain.txt" );
  10. CP( "sample2.txt", "sync_test_03/update.txt" );
  11. CP( "sample2.txt", "sync_test_03/notupdate.tmp" );
  12. CMD( "../npk test.npk -sync sync_test_03 --sa --sd --ig *.tmp --k 1:2:3:4" );
  13. int teakey[4] = {1,2,3,4};
  14. NPK_PACKAGE pack = npk_package_open( "test.npk", teakey );
  15. CHECK( pack != NULL );
  16. NPK_ENTITY entity;
  17. NPK_SIZE size;
  18. void* buf;
  19. entity = npk_package_get_entity( pack, "remain.txt" );
  20. CHECK( entity != NULL );
  21. entity = npk_package_get_entity( pack, "add.txt" );
  22. CHECK( entity != NULL );
  23. entity = npk_package_get_entity( pack, "notadd.tmp" );
  24. CHECK( entity == NULL );
  25. entity = npk_package_get_entity( pack, "notdelete.tmp" );
  26. CHECK( entity != NULL );
  27. entity = npk_package_get_entity( pack, "update.txt" );
  28. CHECK( entity != NULL );
  29. size = npk_entity_get_size( entity );
  30. buf = malloc( size );
  31. CHECK( npk_entity_read( entity, buf ) );
  32. CHECK_EQUAL_STR_WITH_FILE( (const char*)buf, "sample2.txt" );
  33. free( buf );
  34. entity = npk_package_get_entity( pack, "notupdate.tmp" );
  35. CHECK( entity != NULL );
  36. size = npk_entity_get_size( entity );
  37. buf = malloc( size );
  38. CHECK( npk_entity_read( entity, buf ) );
  39. CHECK_EQUAL_STR_WITH_FILE( (const char*)buf, "sample.txt" );
  40. free( buf );
  41. npk_package_close( pack );
  42. return 0;
  43. }