File: cache.cpp

package info (click to toggle)
davix 0.8.10-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 37,184 kB
  • sloc: ansic: 164,612; cpp: 38,741; python: 17,726; perl: 14,124; sh: 13,458; xml: 3,567; makefile: 1,959; javascript: 885; pascal: 570; lisp: 7
file content (60 lines) | stat: -rw-r--r-- 1,334 bytes parent folder | download | duplicates (3)
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
48
49
50
51
52
53
54
55
56
57
58
59
60

#include <iostream>
#include <string>
#include <cstring>
#include <gtest/gtest.h>



#undef A_LIB_NAMESPACE
#define A_LIB_NAMESPACE Davix

#include "libs/alibxx/alibxx.hpp"

using namespace std;

struct DummyStruct{
    std::string dude;
};


// instanciate and play with gates
TEST(ALibxx, CacheTest){



    Davix::Cache<std::string,  DummyStruct> cache;

    ASSERT_TRUE(cache.find("hello").get() == NULL);

    std::shared_ptr<DummyStruct> dumb( new DummyStruct());
    dumb->dude = "bob";

    ASSERT_STREQ("bob",cache.insert("hello", dumb)->dude.c_str());


    ASSERT_STREQ("bob", cache.find("hello")->dude.c_str());
    ASSERT_EQ(1, cache.getSize());
    ASSERT_STREQ("bob", cache.take("hello")->dude.c_str());
    ASSERT_EQ(0, cache.getSize());

    ASSERT_TRUE(cache.find("hello").get() == NULL);

    ASSERT_STREQ("bob",cache.insert("alice", dumb)->dude.c_str());

    ASSERT_STREQ("bob",cache.insert("test", dumb)->dude.c_str());
    ASSERT_STREQ("bob",cache.insert("john", dumb)->dude.c_str());

    ASSERT_STREQ("bob", cache.find("john").get()->dude.c_str());

    ASSERT_EQ(3, cache.getSize());

    ASSERT_TRUE(cache.erase("john"));
    ASSERT_FALSE(cache.erase("john"));

    ASSERT_EQ(2, cache.getSize());
    ASSERT_TRUE( cache.find("john").get() == NULL);

    cache.clear();
    ASSERT_EQ(0, cache.getSize());
}