Project
Loading...
Searching...
No Matches
testMemFileHelper.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
15
16#define BOOST_TEST_MODULE MemFileUtils unit test
17#define BOOST_TEST_MAIN
18#define BOOST_TEST_DYN_LINK
19#include <boost/test/unit_test.hpp>
20#include <filesystem>
21#include <cstdio>
22#include <vector>
23#include <TFile.h>
25
26BOOST_AUTO_TEST_CASE(test_memfile_helper)
27{
28 std::vector<int> vec = {1, 2, 3};
29 std::string fname = "test_MemFile.root";
30 std::string objname = o2::utils::MemFileHelper::getClassName(vec);
31 BOOST_CHECK(!objname.empty());
32 auto img = o2::utils::MemFileHelper::createFileImage(vec, "test_MemFile.root");
33 FILE* fp = fopen(fname.c_str(), "wb");
34 fwrite(img->data(), img->size(), 1, fp);
35 fclose(fp);
36 //
37 // try to read back
38 TFile rdf(fname.c_str());
39 auto* rvec = (std::vector<int>*)rdf.GetObjectChecked(objname.c_str(), objname.c_str());
40 BOOST_CHECK(rvec);
41 BOOST_CHECK(*rvec == vec);
42}
43
45#include <cstdlib>
46
47BOOST_AUTO_TEST_CASE(test_expandenv)
48{
49 {
50 std::string noenv("simple_file.root");
51 auto expandedFileName = o2::utils::expandShellVarsInFileName(noenv);
52 BOOST_CHECK(expandedFileName.size() > 0);
53 BOOST_CHECK_EQUAL(expandedFileName, noenv);
54 }
55
56 {
57 std::string withenv("${PWD}/simple_file.root");
58 auto expandedFileName = o2::utils::expandShellVarsInFileName(withenv);
59 BOOST_CHECK(expandedFileName.size() > 0);
60 }
61
62 {
63 setenv("FOO_123", "BAR", 0);
64 std::string withenv("/tmp/${FOO_123}/simple_file.root");
65 auto expandedFileName = o2::utils::expandShellVarsInFileName(withenv);
66 BOOST_CHECK_EQUAL(expandedFileName, "/tmp/BAR/simple_file.root");
67 }
68
69 { // what if the variable doesn't exist --> should return unmodified string
70 std::string withenv("/tmp/${FOO_DOESNOTEXIST}/simple_file.root");
71 auto expandedFileName = o2::utils::expandShellVarsInFileName(withenv);
72 BOOST_CHECK_EQUAL(expandedFileName, withenv);
73 }
74}
GLint void * img
Definition glcorearb.h:550
std::string expandShellVarsInFileName(std::string const &input)
static std::string getClassName(const T &obj)
get the class name of the object
static std::unique_ptr< FileImage > createFileImage(const TObject &obj, const std::string &fileName, const std::string &objName)
BOOST_AUTO_TEST_CASE(test_memfile_helper)
std::vector< o2::ctf::BufferType > vec
BOOST_CHECK(tree)
BOOST_CHECK_EQUAL(triggersD.size(), triggers.size())