summaryrefslogtreecommitdiffstats
path: root/src/test/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/common')
-rw-r--r--src/test/common/CMakeLists.txt6
-rw-r--r--src/test/common/test_async_shared_mutex.cc1
-rw-r--r--src/test/common/test_htmlformatter.cc26
-rw-r--r--src/test/common/test_intrusive_lru.cc22
-rw-r--r--src/test/common/test_json_formatter.cc24
-rw-r--r--src/test/common/test_tableformatter.cc17
-rw-r--r--src/test/common/test_time.cc2
-rw-r--r--src/test/common/test_xmlformatter.cc22
8 files changed, 112 insertions, 8 deletions
diff --git a/src/test/common/CMakeLists.txt b/src/test/common/CMakeLists.txt
index 33ff38b932d..3c9cf0003aa 100644
--- a/src/test/common/CMakeLists.txt
+++ b/src/test/common/CMakeLists.txt
@@ -229,6 +229,12 @@ add_executable(unittest_xmlformatter
add_ceph_unittest(unittest_xmlformatter)
target_link_libraries(unittest_xmlformatter ceph-common)
+add_executable(unittest_htmlformatter
+ test_htmlformatter.cc
+ )
+add_ceph_unittest(unittest_htmlformatter)
+target_link_libraries(unittest_htmlformatter ceph-common)
+
# unittest_bit_vector
add_executable(unittest_bit_vector
test_bit_vector.cc
diff --git a/src/test/common/test_async_shared_mutex.cc b/src/test/common/test_async_shared_mutex.cc
index ed3a55a70ed..ebd9b937ac8 100644
--- a/src/test/common/test_async_shared_mutex.cc
+++ b/src/test/common/test_async_shared_mutex.cc
@@ -15,6 +15,7 @@
#include "common/async/shared_mutex.h"
#include <future>
#include <optional>
+#include <shared_mutex> // for std::shared_lock
#include <boost/asio/bind_executor.hpp>
#include <boost/asio/io_context.hpp>
#include <gtest/gtest.h>
diff --git a/src/test/common/test_htmlformatter.cc b/src/test/common/test_htmlformatter.cc
new file mode 100644
index 00000000000..0a8d827b53a
--- /dev/null
+++ b/src/test/common/test_htmlformatter.cc
@@ -0,0 +1,26 @@
+#include "gtest/gtest.h"
+
+#include "common/HTMLFormatter.h"
+#include <sstream>
+#include <string>
+
+using namespace ceph;
+
+TEST(htmlformatter, dump_format_large_item)
+{
+ std::stringstream sout;
+ HTMLFormatter formatter(false);
+
+ std::string base_url("http://example.com");
+ std::string bucket_name("bucket");
+ std::string object_key(1024, 'a');
+
+ formatter.dump_format("Location", "%s/%s/%s", base_url.c_str(), bucket_name.c_str(), object_key.c_str());
+
+ formatter.flush(sout);
+
+ std::string uri = base_url + "/" + bucket_name + "/" + object_key;
+ std::string expected_output = "<li>Location: " + uri + "</li>";
+
+ EXPECT_EQ(expected_output, sout.str());
+} \ No newline at end of file
diff --git a/src/test/common/test_intrusive_lru.cc b/src/test/common/test_intrusive_lru.cc
index af8edb8e2bf..1410b73fcaa 100644
--- a/src/test/common/test_intrusive_lru.cc
+++ b/src/test/common/test_intrusive_lru.cc
@@ -177,9 +177,9 @@ TEST(LRU, clear_range) {
auto [live_ref2, existed2] = cache.add(5, 4);
ASSERT_FALSE(existed2);
- cache.clear_range(0,4);
+ cache.clear_range(0, 4, [](auto&){});
- // Should not exists (Unreferenced):
+ // Should not exist
{
auto [ref, existed] = cache.add(1, 4);
ASSERT_FALSE(existed);
@@ -192,21 +192,27 @@ TEST(LRU, clear_range) {
auto [ref, existed] = cache.add(3, 4);
ASSERT_FALSE(existed);
}
- // Should exist (Still being referenced):
{
auto [ref, existed] = cache.add(4, 4);
- ASSERT_TRUE(existed);
+ ASSERT_FALSE(existed);
}
- // Should exists (Still being referenced and wasn't removed)
+ ASSERT_TRUE(live_ref1->is_invalidated());
+ // Should exist, wasn't removed)
{
auto [ref, existed] = cache.add(5, 4);
ASSERT_TRUE(existed);
}
- // Test out of bound deletion:
+ ASSERT_FALSE(live_ref2->is_invalidated());
+ // Test clear_range with right bound past last entry
+ cache.clear_range(3, 8, [](auto&){});
+ ASSERT_TRUE(live_ref2->is_invalidated());
{
- cache.clear_range(3,8);
auto [ref, existed] = cache.add(4, 4);
- ASSERT_TRUE(existed);
+ ASSERT_FALSE(existed);
+ }
+ {
+ auto [ref, existed] = cache.add(5, 4);
+ ASSERT_FALSE(existed);
}
{
auto [ref, existed] = cache.add(3, 4);
diff --git a/src/test/common/test_json_formatter.cc b/src/test/common/test_json_formatter.cc
index 9cc19b24ad1..d0ddd262c0a 100644
--- a/src/test/common/test_json_formatter.cc
+++ b/src/test/common/test_json_formatter.cc
@@ -102,3 +102,27 @@ TEST(formatter, dump_inf_or_nan)
EXPECT_EQ(parser.find_obj("nan_val")->get_data(), "null");
EXPECT_EQ(parser.find_obj("nan_val_alt")->get_data(), "null");
}
+
+TEST(formatter, dump_large_item) {
+ JSONFormatter formatter;
+ formatter.open_object_section("large_item");
+
+ std::string base_url("http://example.com");
+ std::string bucket_name("bucket");
+ std::string object_key(1024, 'a');
+
+ std::string full_url = base_url + "/" + bucket_name + "/" + object_key;
+ formatter.dump_format("Location", "%s/%s/%s", base_url.c_str(), bucket_name.c_str(), object_key.c_str());
+
+ formatter.close_section();
+ bufferlist bl;
+ formatter.flush(bl);
+
+ // std::cout << std::string(bl.c_str(), bl.length()) << std::endl;
+
+ JSONParser parser;
+ parser.parse(bl.c_str(), bl.length());
+
+ EXPECT_TRUE(parser.parse(bl.c_str(), bl.length()));
+ EXPECT_EQ(parser.find_obj("Location")->get_data(), full_url);
+}
diff --git a/src/test/common/test_tableformatter.cc b/src/test/common/test_tableformatter.cc
index b152014a2b5..90de133d315 100644
--- a/src/test/common/test_tableformatter.cc
+++ b/src/test/common/test_tableformatter.cc
@@ -250,6 +250,23 @@ TEST(tableformatter, multiline_keyval)
EXPECT_EQ(cmp, sout.str());
}
+TEST(tableformatter, dump_large_item) {
+ std::stringstream sout;
+ TableFormatter* formatter = (TableFormatter*) Formatter::create("table-kv");
+
+ std::string base_url("http://example.com");
+ std::string bucket_name("bucket");
+ std::string object_key(1024, 'a');
+
+ std::string full_url = base_url + "/" + bucket_name + "/" + object_key;
+ formatter->dump_format("Location", "%s/%s/%s", base_url.c_str(), bucket_name.c_str(), object_key.c_str());
+ formatter->flush(sout);
+ delete formatter;
+
+ std::string cmp = "key::Location=\"" + full_url + "\" \n";
+ EXPECT_EQ(cmp, sout.str());
+}
+
/*
* Local Variables:
* compile-command: "cd ../.. ; make -j4 &&
diff --git a/src/test/common/test_time.cc b/src/test/common/test_time.cc
index bc19ba573d1..80af6fad805 100644
--- a/src/test/common/test_time.cc
+++ b/src/test/common/test_time.cc
@@ -28,6 +28,8 @@ using ceph::real_time;
using ceph::real_clock;
using ceph::real_time;
+using ceph::mono_clock;
+
using ceph::coarse_real_clock;
using ceph::coarse_mono_clock;
diff --git a/src/test/common/test_xmlformatter.cc b/src/test/common/test_xmlformatter.cc
index 9ac6dde456e..abbe9e4e25e 100644
--- a/src/test/common/test_xmlformatter.cc
+++ b/src/test/common/test_xmlformatter.cc
@@ -163,3 +163,25 @@ TEST(xmlformatter, pretty_lowercased_underscored)
"<string_item>String</string_item>\n\n";
EXPECT_EQ(cmp, sout.str());
}
+
+TEST(xmlformatter, dump_format_large_item)
+{
+ std::stringstream sout;
+ XMLFormatter formatter(
+ true, // pretty
+ false, // lowercased
+ false); // underscored
+
+ std::string base_url("http://example.com");
+ std::string bucket_name("bucket");
+ std::string object_key(1024, 'a');
+
+ formatter.dump_format("Location", "%s/%s/%s", base_url.c_str(), bucket_name.c_str(), object_key.c_str());
+
+ formatter.flush(sout);
+
+ std::string uri = base_url + "/" + bucket_name + "/" + object_key;
+ std::string expected_output = "<Location>" + uri + "</Location>\n\n";
+
+ EXPECT_EQ(expected_output, sout.str());
+} \ No newline at end of file