Skip to content

Commit

Permalink
Test compressed cbor input
Browse files Browse the repository at this point in the history
  • Loading branch information
huitema committed Mar 6, 2024
1 parent ab226cc commit bbd9187
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 15 deletions.
8 changes: 8 additions & 0 deletions ithiunit/unittest1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,5 +380,13 @@ namespace ithiunit
Assert::AreEqual(ret, true);
}

TEST_METHOD(IPStatsXZ)
{
IPStatsXZTest test;
bool ret = test.DoTest();

Assert::AreEqual(ret, true);
}

};
}
2 changes: 1 addition & 1 deletion lib/ipstats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ bool IPStats::LoadInputFiles(size_t nb_files, char const** fileNames)
ret = LoadCborFile(fileNames[i]);
}
/* If ends with ".cbor.xz", load as compressed cbor file */
else if (ithi_endswith(fileNames[i], ".cbor.cx")) {
else if (ithi_endswith(fileNames[i], ".cbor.xz")) {
ret = LoadCborCxFile(fileNames[i]);
}
/* If ends with ".csv", load as csv file */
Expand Down
65 changes: 51 additions & 14 deletions test/IPStatsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,45 +29,82 @@
#ifndef _WINDOWS64
static char const * ipstats_test_input = "..\\data\\tiny-capture.cbor";
static char const * ipstats_test_output = "..\\data\\ipstats-tiny-ref.csv";
static char const * ipstats_xz_test_input = "..\\data\\tiny-capture.cbor.xz";
static char const * ipstats_xz_test_output = "..\\data\\ipstats-xz-tiny-ref.csv";
#else
static char const * ipstats_test_input = "..\\..\\data\\tiny-capture.cbor";
static char const * ipstats_test_output = "..\\..\\data\\ipstats-tiny-ref.csv";
static char const * ipstats_xz_test_input = "..\\..\\data\\tiny-capture.cbor.xz";
static char const * ipstats_xz_test_output = "..\\..\\data\\ipstats-xz-tiny-ref.csv";
#endif
#else
static char const * ipstats_test_input = "data/tiny-capture.cbor";
static char const * ipstats_test_output = "data/ipstats-tiny-ref.csv";
static char const * ipstats_xz_test_input = "data/tiny-capture.cbor.xz";
static char const * ipstats_xz_test_output = "data/ipstats-xz-tiny-ref.csv";
#endif
static char const* ip_stats_csv = "tiny-capture-ipstats.csv";
static char const* ip_stats_xz_csv = "tiny-capture-ipstats-xz.csv";


IPStatsTest::IPStatsTest()
{}

IPStatsTest::~IPStatsTest()
{}

bool IPStatsTest::DoTest()
bool IPStatsTestOne(
char const * result_file,
char const * ref_file,
char const** input_files,
size_t nb_input_files
)
{
IPStats ipstats;
char const * list[1] = { ipstats_test_input };
bool ret = ipstats.LoadInputFiles(1, list);
bool ret = ipstats.LoadInputFiles(nb_input_files, input_files);

if (!ret){
TEST_LOG("Cannot process the CBOR input file: %s\n", list[0]);
TEST_LOG("Cannot process the input file: %s\n", input_files[0]);
}
else
{
ret = ipstats.SaveToCsv(ip_stats_csv);
ret = ipstats.SaveToCsv(result_file);
if (!ret) {
TEST_LOG("Cannot save to csv file: %s.\n", ip_stats_csv);
TEST_LOG("Cannot save to csv file: %s.\n", result_file);
}
else {
TEST_LOG("IP Stats have been saved to %s\n", ip_stats_csv);
ret = MetricTest::compare_files(ip_stats_csv, ipstats_test_output);
TEST_LOG("IP Stats have been saved to %s\n", result_file);

ret = MetricTest::compare_files(result_file, ref_file);
}
}

return ret;
}

IPStatsTest::IPStatsTest()
{}

IPStatsTest::~IPStatsTest()
{}

bool IPStatsTest::DoTest()
{
char const * list[1] = { ipstats_test_input };

bool ret = IPStatsTestOne(ip_stats_csv, ipstats_test_output, list, 1);

return ret;
}


IPStatsXZTest::IPStatsXZTest()
{}

IPStatsXZTest::~IPStatsXZTest()
{}

bool IPStatsXZTest::DoTest()
{
IPStats ipstats;
char const * list[1] = { ipstats_xz_test_input };

bool ret = IPStatsTestOne(ip_stats_xz_csv, /* TODO: change! */ ipstats_test_output, list, 1);

return ret;
}
10 changes: 10 additions & 0 deletions test/IPStatsTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,15 @@ class IPStatsTest : public ithi_test_class
bool DoTest() override;
};

class IPStatsXZTest : public ithi_test_class
{
public:
IPStatsXZTest();
~IPStatsXZTest();

bool DoTest() override;
};


#endif /* SAVE_TEST_H */

5 changes: 5 additions & 0 deletions test/ithi_test_class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ enum test_list_enum {
test_enum_TrailingZeroes,
test_enum_HyperLogLog,
test_enum_IPStats,
test_enum_IPStatsXZ,
test_enum_max_number,
};

Expand Down Expand Up @@ -178,6 +179,8 @@ char const * ithi_test_class::GetTestName(int number)
return("HyperLogLog");
case test_enum_IPStats:
return("IPStats");
case test_enum_IPStatsXZ:
return("IPStatsXZ");
default:
break;
}
Expand Down Expand Up @@ -330,6 +333,8 @@ ithi_test_class * ithi_test_class::TestByNumber(int number)
case test_enum_IPStats:
test = new IPStatsTest();
break;
case test_enum_IPStatsXZ:
test = new IPStatsXZTest();
default:
break;
}
Expand Down

0 comments on commit bbd9187

Please sign in to comment.