Celestia

Форк
0
/
cmod_bin_ascii_roundtrip_test.cpp 
61 строка · 1.8 Кб
1
#include <algorithm>
2
#include <fstream>
3
#include <ios>
4
#include <iterator>
5
#include <memory>
6
#include <sstream>
7
#include <vector>
8

9
#include <doctest.h>
10

11
#include <celcompat/filesystem.h>
12
#include <celmodel/model.h>
13
#include <celmodel/modelfile.h>
14
#include <celutil/reshandle.h>
15

16
TEST_SUITE_BEGIN("CMOD integration");
17

18
TEST_CASE("CMOD binary to ASCII roundtrip")
19
{
20
    std::vector<fs::path> paths;
21
    cmod::HandleGetter handleGetter = [&](const fs::path& path)
22
    {
23
        auto it = std::find(paths.cbegin(), paths.cend(), path);
24
        if (it == paths.cend())
25
        {
26
            paths.push_back(path);
27
            return static_cast<ResourceHandle>(paths.size() - 1);
28
        }
29
        else
30
        {
31
            return static_cast<ResourceHandle>(it - paths.cbegin());
32
        }
33
    };
34
    cmod::SourceGetter sourceGetter = [&](ResourceHandle handle) { return paths[handle]; };
35

36
    std::ifstream f("testmodel.cmod", std::ios::in | std::ios::binary);
37
    REQUIRE(f.good());
38
    std::stringstream sourceData;
39
    sourceData << f.rdbuf();
40

41
    std::unique_ptr<cmod::Model> modelFromBinary = cmod::LoadModel(sourceData, handleGetter);
42
    REQUIRE(modelFromBinary != nullptr);
43

44
    std::stringstream asciiData;
45
    REQUIRE(cmod::SaveModelAscii(modelFromBinary.get(), asciiData, sourceGetter));
46

47
    std::unique_ptr<cmod::Model> modelFromAscii = cmod::LoadModel(asciiData, handleGetter);
48
    REQUIRE(modelFromAscii != nullptr);
49

50
    std::stringstream roundtrippedData;
51
    REQUIRE(cmod::SaveModelBinary(modelFromAscii.get(), roundtrippedData, sourceGetter));
52

53
    sourceData.clear();
54
    REQUIRE(sourceData.seekg(0, std::ios_base::beg).good());
55

56
    std::istreambuf_iterator<char> end;
57
    REQUIRE(std::equal(std::istreambuf_iterator<char>(sourceData), end,
58
                       std::istreambuf_iterator<char>(roundtrippedData), end));
59
}
60

61
TEST_SUITE_END();
62

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.