PageRenderTime 15ms CodeModel.GetById 10ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 6int libnpk_export( int argc, char * argv [] )
 7{
 8    int teakey[4] = {98521,16322,7163,992};
 9
10    NPK_PACKAGE pack = npk_package_open( "sample.npk", teakey );
11    CHECK( pack != NULL );
12
13    std::string entityNames[4] = { "sample.txt", "zip.txt", "tea.txt", "zipntea.txt" };
14
15    for( int i = 0; i < 4; ++i )
16    {
17        NPK_ENTITY entity = npk_package_get_entity( pack, entityNames[i].c_str() );
18        CHECK( entity != NULL );
19
20        std::string exported = "exported." + entityNames[i];
21        CHECK( NPK_SUCCESS == npk_entity_export( entity, exported.c_str(), true ) );
22
23        NPK_SIZE size = npk_entity_get_size( entity );
24        void* buf = malloc( size );
25
26        CHECK( npk_entity_read( entity, buf ) );
27        CHECK_EQUAL_STR_WITH_FILE( (const char*)buf, exported.c_str() );
28
29        free( buf );
30    }
31
32    npk_package_close( pack );
33    return 0;
34}