merge changes from 1.10.2

This commit is contained in:
Günter Obiltschnig
2021-04-11 16:31:35 +02:00
parent 5187f9d0d2
commit cb6e801537
8 changed files with 76 additions and 36 deletions

View File

@@ -176,6 +176,23 @@ public:
return result;
}
template <typename Fn>
void forEach(Fn&& fn) const
/// Iterates over all key-value pairs in the
/// cache, using a functor or lambda expression.
///
/// The given functor must take the key and value
/// as parameters. Note that the value is passed
/// as the actual value (or reference),
/// not a Poco::SharedPtr.
{
typename TMutex::ScopedLock lock(_mutex);
for (const auto& p: _data)
{
fn(p.first, *p.second);
}
}
protected:
mutable FIFOEvent<ValidArgs<TKey>> IsValid;
mutable FIFOEvent<KeySet> Replace;

View File

@@ -49,8 +49,7 @@ void writeString(const std::string &value, T& obj, typename WriteFunc<T, S>::Typ
{
for(std::string::const_iterator it = value.begin(), end = value.end(); it != end; ++it)
{
// Forward slash isn't strictly required by JSON spec, but some parsers expect it
if((*it >= 0 && *it <= 31) || (*it == '"') || (*it == '\\') || (*it == '/'))
if((*it >= 0 && *it <= 31) || (*it == '"') || (*it == '\\'))
{
std::string str = Poco::UTF8::escape(it, it + 1, true);
(obj.*write)(str.c_str(), str.size());

View File

@@ -221,6 +221,29 @@ void LRUCacheTest::testUpdate()
}
void LRUCacheTest::testForEach()
{
LRUCache<int, int> aCache(3);
std::map<int, int> values;
aCache.add(1, 100);
aCache.add(2, 200);
aCache.add(3, 300);
aCache.forEach(
[&values](int key, int value)
{
values[key] = value;
}
);
assertEquals (values.size(), 3);
assertEquals (values[1], 100);
assertEquals (values[2], 200);
assertEquals (values[3], 300);
}
void LRUCacheTest::onUpdate(const void* pSender, const Poco::KeyValueArgs<int, int>& args)
{
++updateCnt;
@@ -260,6 +283,7 @@ CppUnit::Test* LRUCacheTest::suite()
CppUnit_addTest(pSuite, LRUCacheTest, testCacheSizeN);
CppUnit_addTest(pSuite, LRUCacheTest, testDuplicateAdd);
CppUnit_addTest(pSuite, LRUCacheTest, testUpdate);
CppUnit_addTest(pSuite, LRUCacheTest, testForEach);
return pSuite;
}

View File

@@ -31,6 +31,7 @@ public:
void testCacheSizeN();
void testDuplicateAdd();
void testUpdate();
void testForEach();
void setUp();
void tearDown();

View File

@@ -1378,7 +1378,6 @@ void StringTest::testJSONString()
{
assertTrue (toJSON("\\", false) == "\\\\");
assertTrue (toJSON("\"", false) == "\\\"");
assertTrue (toJSON("/", false) == "\\/");
assertTrue (toJSON("\a", false) == "\\u0007");
assertTrue (toJSON("\b", false) == "\\b");
assertTrue (toJSON("\f", false) == "\\f");
@@ -1395,7 +1394,7 @@ void StringTest::testJSONString()
std::string str = "\"foo\\\\\"";
assertTrue (toJSON("foo\\") == str);
assertTrue (toJSON("bar/") == "\"bar\\/\"");
assertTrue (toJSON("bar/") == "\"bar/\"");
assertTrue (toJSON("baz") == "\"baz\"");
assertTrue (toJSON("q\"uote\"d") == "\"q\\\"uote\\\"d\"");
assertTrue (toJSON("bs\b") == "\"bs\\b\"");
@@ -1412,7 +1411,7 @@ void StringTest::testJSONString()
ostr.str("");
toJSON("foo\\", ostr);
assertTrue (toJSON("bar/") == "\"bar\\/\"");
assertTrue (toJSON("bar/") == "\"bar/\"");
ostr.str("");
toJSON("baz", ostr);
assertTrue (ostr.str() == "\"baz\"");

View File

@@ -2625,7 +2625,7 @@ void VarTest::testJSONDeserializeString()
tst = "{ \"message\": \"escape\\b\\f\\n\\r\\t\", \"path\": \"\\/dev\\/null\" }";
a = Var::parse(tst);
assertTrue(a.toString() == "{ \"message\" : \"escape\\b\\f\\n\\r\\t\", \"path\" : \"\\/dev\\/null\" }");
assertTrue(a.toString() == "{ \"message\": \"escape\\b\\f\\n\\r\\t\", \"path\": \"/dev/null\" }");
}