| 1 |
#include <pbcopper/reports/Report.h> |
| 2 |
|
| 3 |
#include <sstream> |
| 4 |
#include <string> |
| 5 |
#include <vector> |
| 6 |
|
| 7 |
#include <gtest/gtest.h> |
| 8 |
|
| 9 |
#include <pbcopper/json/JSON.h> |
| 10 |
#include <pbcopper/utility/PbcopperVersion.h> |
| 11 |
|
| 12 |
using namespace PacBio; |
| 13 |
using namespace PacBio::Reports; |
| 14 |
|
| 15 |
namespace ReportsTests { |
| 16 |
|
| 17 |
Report MakeReport() |
| 18 |
{ |
| 19 |
const int foo_value = 3; |
| 20 |
const std::string bar_value = "test"; |
| 21 |
const double baz_value = 0.75; |
| 22 |
|
| 23 |
Report report{"isoseq3_flnca", "Report isoseq3"}; |
| 24 |
report.Attributes({{"foo", foo_value, "Foo Title"}, |
| 25 |
{"bar", bar_value, "Bar Title"}, |
| 26 |
{"baz", baz_value, "Baz Title"}}); |
| 27 |
report.Uuid("testable_uuid"); |
| 28 |
|
| 29 |
Table table{"table1"}; |
| 30 |
table.AddColumn(Column{"col1", std::vector<ReportValue>{1, 2, 3, 4}}); |
| 31 |
report.AddTable(table); |
| 32 |
|
| 33 |
return report; |
| 34 |
} |
| 35 |
|
| 36 |
} // namespace ReportsTests |
| 37 |
|
| 38 |
// clang-format off |
| 39 |
TEST(Reports_Report, can_print_pbreport) |
| 40 |
{ |
| 41 |
std::string expectedText{R"({ |
| 42 |
"_comment": "Created by pbcopper v____", |
| 43 |
"attributes": [ |
| 44 |
{ |
| 45 |
"id": "foo", |
| 46 |
"name": "Foo Title", |
| 47 |
"value": 3 |
| 48 |
}, |
| 49 |
{ |
| 50 |
"id": "bar", |
| 51 |
"name": "Bar Title", |
| 52 |
"value": "test" |
| 53 |
}, |
| 54 |
{ |
| 55 |
"id": "baz", |
| 56 |
"name": "Baz Title", |
| 57 |
"value": 0.75 |
| 58 |
} |
| 59 |
], |
| 60 |
"dataset_uuids": [], |
| 61 |
"id": "isoseq3_flnca", |
| 62 |
"plotGroups": [], |
| 63 |
"tables": [ |
| 64 |
{ |
| 65 |
"columns": [ |
| 66 |
{ |
| 67 |
"header": "", |
| 68 |
"id": "col1", |
| 69 |
"values": [ |
| 70 |
1, |
| 71 |
2, |
| 72 |
3, |
| 73 |
4 |
| 74 |
] |
| 75 |
} |
| 76 |
], |
| 77 |
"id": "table1", |
| 78 |
"title": "" |
| 79 |
} |
| 80 |
], |
| 81 |
"title": "Report isoseq3", |
| 82 |
"uuid": "testable_uuid", |
| 83 |
"version": "1.0.1" |
| 84 |
})"}; |
| 85 |
expectedText.replace(40, 4, PacBio::Utility::LibraryVersionString()); |
| 86 |
|
| 87 |
std::ostringstream s; |
| 88 |
const auto report = ReportsTests::MakeReport(); |
| 89 |
report.Print(s); |
| 90 |
EXPECT_EQ(expectedText, s.str()); |
| 91 |
} |
| 92 |
|
| 93 |
TEST(Reports_Report, can_print_summary) |
| 94 |
{ |
| 95 |
const std::string expectedText{R"({ |
| 96 |
"bar": "test", |
| 97 |
"baz": 0.75, |
| 98 |
"foo": 3 |
| 99 |
})"}; |
| 100 |
|
| 101 |
std::ostringstream s; |
| 102 |
const auto report = ReportsTests::MakeReport(); |
| 103 |
report.PrintSummary(s); |
| 104 |
EXPECT_EQ(expectedText, s.str()); |
| 105 |
} |
| 106 |
// clang-format on |
| 107 |
|
| 108 |
TEST(Reports_Report, can_write_task_report) |
| 109 |
{ |
| 110 |
const TaskReport report{16, 100, 0, 4096}; |
| 111 |
std::ostringstream s; |
| 112 |
report.Print(s); |
| 113 |
|
| 114 |
EXPECT_NE(s.str().find("Task Report"), std::string::npos); |
| 115 |
EXPECT_NE(s.str().find("Number of cores/slots"), std::string::npos); |
| 116 |
EXPECT_NE(s.str().find("Run time (seconds)"), std::string::npos); |
| 117 |
EXPECT_NE(s.str().find("Exit code"), std::string::npos); |
| 118 |
EXPECT_NE(s.str().find("Peak RSS (GB)"), std::string::npos); |
| 119 |
} |
| 120 |
|
| 121 |
TEST(Reports_Report, can_report_longints) |
| 122 |
{ |
| 123 |
EXPECT_EQ(0, 0); |
| 124 |
Report report{"isoseq3_flnca", "Report isoseq3"}; |
| 125 |
// clang-format off |
| 126 |
report.Attributes({ |
| 127 |
{"foo", 0xffffffffu, "Foo Title for uint32_t"}, |
| 128 |
{"bar", static_cast<int64_t>(0xffffffffffff), "Bar Title for long long"}, |
| 129 |
{"bar2", static_cast<int64_t>(1) << 62, "Bar Title for long long"}, |
| 130 |
}); |
| 131 |
report.Uuid("fakeitem"); |
| 132 |
// clang-format on |
| 133 |
|
| 134 |
// serialize |
| 135 |
std::stringstream s; |
| 136 |
report.Print(s); |
| 137 |
|
| 138 |
// deserialize |
| 139 |
JSON::Json doc; |
| 140 |
s >> doc; |
| 141 |
ASSERT_TRUE(doc.is_object()); |
| 142 |
const JSON::Json attributes = doc["attributes"]; |
| 143 |
ASSERT_TRUE(attributes.is_array()); |
| 144 |
for (const auto& attribute : attributes) { |
| 145 |
ASSERT_TRUE(attribute.is_object()); |
| 146 |
const std::string id = attribute["id"]; |
| 147 |
if (id == "foo") { |
| 148 |
ASSERT_EQ(attribute["value"], 4294967295); |
| 149 |
} else if (id == "bar") { |
| 150 |
ASSERT_EQ(attribute["value"], 281474976710655); |
| 151 |
} else if (id == "bar2") { |
| 152 |
ASSERT_EQ(attribute["value"], 4611686018427387904); |
| 153 |
} else { |
| 154 |
ASSERT_EQ("unexpected_id", id); |
| 155 |
} |
| 156 |
} |
| 157 |
} |