/libnpk/tests/libnpk_export.cpp

http://npk.googlecode.com/ · C++ · 34 lines · 25 code · 9 blank · 0 comment · 4 complexity · 647aefd049f0b44ae19a5dfc70baa0d7 MD5 · raw file

  1. #include "testutil.h"
  2. #include <string>
  3. #include <npk.h>
  4. #include <npk_dev.h>
  5. int libnpk_export( int argc, char * argv [] )
  6. {
  7. int teakey[4] = {98521,16322,7163,992};
  8. NPK_PACKAGE pack = npk_package_open( "sample.npk", teakey );
  9. CHECK( pack != NULL );
  10. std::string entityNames[4] = { "sample.txt", "zip.txt", "tea.txt", "zipntea.txt" };
  11. for( int i = 0; i < 4; ++i )
  12. {
  13. NPK_ENTITY entity = npk_package_get_entity( pack, entityNames[i].c_str() );
  14. CHECK( entity != NULL );
  15. std::string exported = "exported." + entityNames[i];
  16. CHECK( NPK_SUCCESS == npk_entity_export( entity, exported.c_str(), true ) );
  17. NPK_SIZE size = npk_entity_get_size( entity );
  18. void* buf = malloc( size );
  19. CHECK( npk_entity_read( entity, buf ) );
  20. CHECK_EQUAL_STR_WITH_FILE( (const char*)buf, exported.c_str() );
  21. free( buf );
  22. }
  23. npk_package_close( pack );
  24. return 0;
  25. }