diff --git a/store/common/backend/Rules.mk b/store/common/backend/Rules.mk index 2b48d24e2ffe9ae8a2de728c4bf3149cec45ed23..4541dfc7d96efbf4f2e66636df8d913ad2a2abe9 100644 --- a/store/common/backend/Rules.mk +++ b/store/common/backend/Rules.mk @@ -4,3 +4,5 @@ SRCS += $(addprefix $(d), \ kvstore.cc lockserver.cc versionstore.cc) LIB-backend := $(o)kvstore.o $(o)versionstore.o $(o)lockserver.o + +include $(d)tests/Rules.mk \ No newline at end of file diff --git a/store/common/backend/tests/Rules.mk b/store/common/backend/tests/Rules.mk new file mode 100644 index 0000000000000000000000000000000000000000..f79b779cc602282ef9cb2cb941d63e54f7717eb8 --- /dev/null +++ b/store/common/backend/tests/Rules.mk @@ -0,0 +1,11 @@ +d := $(dir $(lastword $(MAKEFILE_LIST))) + +# +# gtest-based tests +# +GTEST_SRCS += $(addprefix $(d), \ + kvstore-test.cc) + +$(d)kvstore-test: $(o)kvstore-test.o $(LIB-transport) $(LIB-common) $(LIB-backend) $(GTEST_MAIN) + +TEST_BINS += $(d)kvstore-test \ No newline at end of file diff --git a/store/common/backend/tests/kvstore-test.cc b/store/common/backend/tests/kvstore-test.cc new file mode 100644 index 0000000000000000000000000000000000000000..0fc9167b7b4fb96685d4f54fd548390c2440fd81 --- /dev/null +++ b/store/common/backend/tests/kvstore-test.cc @@ -0,0 +1,62 @@ +// -*- mode: c++; c-file-style: "k&r"; c-basic-offset: 4 -*- +/*********************************************************************** + * + * kvstore-test.cc: + * test cases for simple key-value store class + * + * Copyright 2015 Irene Zhang <iyzhang@cs.washington.edu> + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + **********************************************************************/ + +#include "store/common/backend/kvstore.h" + +#include <gtest/gtest.h> + +TEST(KVStore, Put) +{ + KVStore store; + + EXPECT_TRUE(store.put("test1", "abc")); + EXPECT_TRUE(store.put("test2", "def")); + EXPECT_TRUE(store.put("test1", "xyz")); + EXPECT_TRUE(store.put("test3", "abc")); +} + +TEST(KVStore, Get) +{ + KVStore store; + std::string val; + + EXPECT_TRUE(store.put("test1", "abc")); + EXPECT_TRUE(store.get("test1", val)); + EXPECT_EQ(val, "abc"); + + EXPECT_TRUE(store.put("test2", "def")); + EXPECT_TRUE(store.get("test2", val)); + EXPECT_EQ(val, "def"); + + EXPECT_TRUE(store.put("test1", "xyz")); + EXPECT_TRUE(store.get("test1", val)); + EXPECT_EQ(val, "xyz"); +} +