Line data Source code
1 : #include <fas/testing.hpp>
2 : #include <demo/domain/demo_domain.hpp>
3 : #include <hash/domain/hash_domain.hpp>
4 : #include <wfc/module/testing_domain.hpp>
5 :
6 3 : UNIT(demo1, "")
7 : {
8 : using namespace fas::testing;
9 1 : t << nothing;
10 1 : auto ptest = std::make_shared<wfc::testing_domain>();
11 2 : demo::storage_domain::domain_config conf;
12 1 : conf.name = "demo1";
13 1 : conf.hash_target = "hash1";
14 2 : auto pdemo = ptest->create<demo::storage_domain>(conf);
15 :
16 2 : auto set=std::make_unique<demo::request::set>();
17 1 : set->key="key1";
18 1 : set->value="val1";
19 2 : pdemo->set(std::move(set), [&t](demo::response::set::ptr res){
20 : using namespace fas::testing;
21 1 : t << is_true<expect>(res->status) << FAS_FL;
22 1 : });
23 :
24 2 : auto get=std::make_unique<demo::request::get>();
25 1 : get->key="key1";
26 2 : pdemo->get(std::move(get), [&t](demo::response::get::ptr res){
27 : using namespace fas::testing;
28 1 : t << equal<expect>(res->value, "val1") << FAS_FL;
29 1 : });
30 :
31 2 : auto get_hashed=std::make_unique<demo::request::get_hashed>();
32 1 : get_hashed->key="key1";
33 2 : pdemo->get_hashed(std::move(get_hashed), [&t](demo::response::get_hashed::ptr res){
34 : using namespace fas::testing;
35 1 : t << equal<assert>(res, nullptr) << FAS_FL;
36 1 : });
37 :
38 2 : demo::hash::hash_domain::domain_config hash_conf;
39 1 : hash_conf.name = "hash1";
40 2 : auto phash = ptest->create<demo::hash::hash_domain>(hash_conf);
41 1 : ptest->initialize();
42 :
43 1 : get_hashed=std::make_unique<demo::request::get_hashed>();
44 1 : get_hashed->key="key1";
45 2 : pdemo->get_hashed(std::move(get_hashed), [&t](demo::response::get_hashed::ptr res){
46 : using namespace fas::testing;
47 :
48 1 : t << not_equal<assert, demo::response::get_hashed::ptr>(res, nullptr) << FAS_FL;
49 1 : t << stop;
50 1 : t << not_equal<assert, size_t>(res->value, std::hash<std::string>()("key1") ) << FAS_FL;
51 1 : t << equal<assert>(res->value, std::hash<std::string>()("val1") ) << FAS_FL;
52 2 : });
53 1 : }
54 :
55 1 : BEGIN_SUITE(demo, "")
56 : ADD_UNIT(demo1)
57 7 : END_SUITE(demo)
|