-
Notifications
You must be signed in to change notification settings - Fork 0
/
SimplCache.cpp
47 lines (35 loc) · 1.15 KB
/
SimplCache.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "SimplCache.h"
#define CATCH_CONFIG_MAIN
#include "catch.h"
static int TestSimplCache(int i)
{
return i;
}
TEST_CASE("SimplCache Unit Test", "[SimplCache UT]") {
struct TICstruct
{
std::string key;
std::string value;
TICstruct() = default;
TICstruct(const std::string& _key, const std::string& _value) :key(_key), value(_value)
{}
std::string& GetKey() { return value; }
bool operator==(const TICstruct& ts) { return (this->key == ts.key && this->value == ts.value); }
};
TICstruct tmem1("test1", "test1"), tmem2("test2", "test2");
SimplCache<TICstruct> tCache;
tCache.PutByKey(tmem1);
tCache.PutByKey(tmem2);
TICstruct tmem3;
REQUIRE(tCache.size() == 2);
REQUIRE(tCache.GetByKey("test1", tmem3) == true);
REQUIRE(tmem3 == tmem1);
REQUIRE(tCache.GetByKey("test4", tmem3) == false);
SimplCache<std::shared_ptr<TICstruct>> stCache;
std::shared_ptr<TICstruct> sptr(std::make_shared<TICstruct>("stest1", "stest1"));
std::shared_ptr<TICstruct> sptr1;
stCache.PutByKey(sptr);
REQUIRE(stCache.size() == 1);
REQUIRE(stCache.GetByKey("stest1", sptr1) == true);
REQUIRE(sptr1 == sptr);
}