Project
Loading...
Searching...
No Matches
test_Objects.cxx
Go to the documentation of this file.
1// Copyright 2019-2026 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
12#include "AODNative/Errors.h"
13#include "AODNative/Objects.h"
14#include "Cursor.h"
15#include "RootFraming.h"
16#include <catch_amalgamated.hpp>
17
18using namespace o2::aod::native;
19using namespace o2::aod::native::test;
20
21TEST_CASE("Cursor reads big-endian integers")
22{
23 std::vector<uint8_t> buf{0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
24 std::string file = "memory";
25 Cursor c{buf, file};
26 CHECK(c.u16() == 0x1234);
27 CHECK(c.u32() == 0x56789abc);
28 CHECK(c.u8() == 0xde);
29 CHECK(c.u64() == 0xf001020304050607ULL);
30 CHECK(c.remaining() == 0);
31 CHECK_THROWS_AS(c.u8(), CorruptData);
32}
33
34TEST_CASE("Cursor reads both TString encodings")
35{
37 w.string("short");
38 w.bytes.push_back(0xFF);
39 w.put<uint32_t>(300);
40 w.bytes.insert(w.bytes.end(), 300, 'x');
41 std::string file = "memory";
42 Cursor c{w.bytes, file};
43 CHECK(c.string() == "short");
44 CHECK(c.string() == std::string(300, 'x'));
45 CHECK(c.remaining() == 0);
46}
47
48TEST_CASE("Cursor never reads out of bounds")
49{
50 std::vector<uint8_t> buf{0x05, 'a', 'b'}; // TString claiming 5 bytes, only 2 there
51 std::string file = "memory";
52 Cursor c{buf, file};
53 CHECK_THROWS_AS(c.string(), CorruptData);
54 Cursor d{buf, file};
55 CHECK_THROWS_AS(d.seek(4), CorruptData);
56 CHECK_THROWS_AS(d.skip(4), CorruptData);
57 Cursor e{buf, file};
58 CHECK_THROWS_AS(e.cstring(), CorruptData);
59}
60
61TEST_CASE("Cursor reports displacement relative to the key")
62{
63 std::vector<uint8_t> buf(10);
64 std::string file = "memory";
65 Cursor c{buf, file, 1000, 64};
66 c.skip(4);
67 CHECK(c.displacement() == 68);
68}
69
70TEST_CASE("truncated tree payloads raise errors, never crash")
71{
72 // Arbitrary bytes, then every truncation of them: each must fail cleanly.
73 std::vector<uint8_t> junk(200);
74 for (size_t i = 0; i < junk.size(); ++i) {
75 junk[i] = (uint8_t)(i * 37 + 11);
76 }
77 // A plausible start: byte count with the flag set, TTree version 20.
78 junk[0] = 0x40;
79 junk[4] = 0x00;
80 junk[5] = 20;
81 for (size_t n = 0; n <= junk.size(); n += 7) {
82 std::span<const uint8_t> part{junk.data(), n};
83 CHECK_THROWS_AS(readTreePayload(part, 64, "memory", 0), FormatError);
84 }
85}
86
87TEST_CASE("unknown class versions raise UnsupportedVersion")
88{
90 w.put<uint32_t>(0x40000000 | 100); // byte count
91 w.put<uint16_t>(19); // TTree version 19: not supported
92 w.bytes.resize(104);
93 CHECK_THROWS_AS(readTreePayload(w.bytes, 64, "memory", 0), UnsupportedVersion);
94}
95
96TEST_CASE("leaf element sizes")
97{
98 CHECK(leafElementSize('O') == 1);
99 CHECK(leafElementSize('B') == 1);
100 CHECK(leafElementSize('S') == 2);
101 CHECK(leafElementSize('I') == 4);
102 CHECK(leafElementSize('F') == 4);
103 CHECK(leafElementSize('L') == 8);
104 CHECK(leafElementSize('D') == 8);
105 CHECK_THROWS_AS(leafElementSize('C'), UnsupportedLayout);
106}
unsigned short int uint16_t
int32_t i
configStandalone Light OpenGL display display_light Apply smoothing to points Enable Z buffer Highlight links Highlight seeds Highlight sector tracks Highlight final tracks Show individual Show related Highlight grid Show only individual collision Color clusters belonging to track objects Set line Enable drawing TPC data Enable drawing TOF data Enable drawing magnetic field Set field line step count Invert colors configStandalone Heavy OpenGL display display_heavy Show tracks with ITS contribution Show tracks with TOF contribution Enable propagation of loopers Show clusters at nominal x of pad row for early transformed data Split CE tracks when they cross the central Mark clusters Mark adjacent clusters Hide rejected tracks Apply filter on tracks to be displayed Separate increase X h configStandalone Camera window renderer OpenGL display display_camera Orient the camera such that the y axis is always upwards Full Screen MultiSample Anti Downsampling Anti Enable Vertical Sync Target frame or if the backend cannot limit to the refresh Use OpenGL indirect draws to reduce number of draw calls Display h configStandalone Vulkan display display_vulkan Have uniform buffers in host accessible device memory h configStandalone Internal display display_internal Number of updates the Qt GUI may send ahead of the last one the display has before it waits for the display Opacity of the console background Number of console lines the history is shortened to this when it reaches twice the size Time in seconds an info message fades out after setInfoTime h OpenGL display display Font size Do not use Freetype for font Renderer for event Frontend to use for event ROOT macros used as track filter Console script file
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char e
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char Directory with events to Events directory is and not inside events d
uint32_t c
Definition RawData.h:2
#define CHECK
GLdouble n
Definition glcorearb.h:1982
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition glcorearb.h:2514
GLubyte GLubyte GLubyte GLubyte w
Definition glcorearb.h:852
TreeInfo readTreePayload(std::span< const uint8_t > payload, uint16_t keylen, std::string const &file, uint64_t fileOffset)
Definition Objects.cxx:534
size_t leafElementSize(char leafClass)
Size in bytes of one value of a leaf class on disk.
Definition Objects.cxx:493
A class version we have no hardcoded layout for.
Definition Errors.h:29
TEST_CASE("Cursor reads big-endian integers")