File: reader_tests.cpp

package info (click to toggle)
protozero 1.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,548 kB
  • sloc: cpp: 20,364; sh: 18; makefile: 14
file content (32 lines) | stat: -rw-r--r-- 856 bytes parent folder | download | duplicates (3)
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

#include <cstdlib>
#include <fstream>
#include <iterator>
#include <stdexcept>
#include <string>

#define CATCH_CONFIG_MAIN
#include <test.hpp> // IWYU pragma: keep

std::string load_data(const std::string& filename) {
    const char* tests_dir = std::getenv("TESTS_DIR"); // NOLINT(concurrency-mt-unsafe) okay in test
    if (tests_dir == nullptr) {
        tests_dir = "test";
    }

    std::string fullname{tests_dir};
    fullname += "/t/";
    fullname += filename;
    fullname += ".pbf";

    std::ifstream stream{fullname, std::ios_base::in | std::ios_base::binary};
    if (!stream.is_open()) {
        throw std::runtime_error{"could not open: '" + filename + "'"};
    }
    std::string buffer{std::istreambuf_iterator<char>(stream.rdbuf()),
                       std::istreambuf_iterator<char>()};
    stream.close();

    return buffer;
}