aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/archive/directory_models_archive_reader_ut.cpp
blob: 92b710a4950227745b42968ba0f306cb93faee14 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "directory_models_archive_reader.h" 
 
#include <library/cpp/testing/unittest/registar.h>
 
#include <util/folder/tempdir.h> 
#include <util/string/cast.h> 
#include <util/stream/file.h> 
#include <util/system/tempfile.h> 
#include <util/memory/blob.h> 
 
class TDirectoryModelsArchiveReaderTest: public TTestBase { 
    UNIT_TEST_SUITE(TDirectoryModelsArchiveReaderTest) 
    UNIT_TEST(TestRead); 
    UNIT_TEST_SUITE_END(); 
 
private: 
    void TestRead(); 
}; 
 
UNIT_TEST_SUITE_REGISTRATION(TDirectoryModelsArchiveReaderTest); 
 
const TString MAIN_DIR = "./dir"; 
const TString SUBDIR = "/subdir"; 
const TString SAMPLE_FILE1 = "/sample1"; 
const TString SAMPLE_FILE2 = "/sample2"; 
const TString TEST_TEXT = "Test Text."; 
 
void TDirectoryModelsArchiveReaderTest::TestRead() { 
    TTempDir mainDir(MAIN_DIR); 
    TTempDir subDir(MAIN_DIR + SUBDIR); 
    TTempFileHandle file1(MAIN_DIR + SAMPLE_FILE1); 
    TTempFileHandle file2(MAIN_DIR + SUBDIR + SAMPLE_FILE2); 
 
    file1.Write(TEST_TEXT.data(), TEST_TEXT.size()); 
    file1.FlushData(); 
 
    TDirectoryModelsArchiveReader reader(MAIN_DIR, false); 
 
    UNIT_ASSERT_EQUAL(reader.Count(), 2); 
 
    UNIT_ASSERT(reader.Has(SAMPLE_FILE1)); 
    UNIT_ASSERT(reader.Has(SUBDIR + SAMPLE_FILE2)); 
 
    UNIT_ASSERT_EQUAL(reader.KeyByIndex(0), SAMPLE_FILE1); 
    UNIT_ASSERT_EQUAL(reader.KeyByIndex(1), SUBDIR + SAMPLE_FILE2); 
 
    TBlob blob = reader.BlobByKey(SAMPLE_FILE1); 
    Cout << "'" << TString(blob.AsCharPtr(), blob.Size()) << "' - '" << TEST_TEXT << "'" << Endl; 
    UNIT_ASSERT_VALUES_EQUAL(TString(blob.AsCharPtr(), blob.Size()), TString(TEST_TEXT)); 
 
    TAutoPtr<IInputStream> is = reader.ObjectByKey(SAMPLE_FILE1); 
    const TString data = is->ReadAll(); 
    Cout << "'" << data << "' - '" << TEST_TEXT << "'" << Endl; 
    UNIT_ASSERT_VALUES_EQUAL(data, TEST_TEXT); 
}