Commit 4b57a797 authored by Yoshitaka Aharen's avatar Yoshitaka Aharen
Browse files

[510] move initialization in every test case into fixture

parent 60fd2937
......@@ -30,18 +30,25 @@ enum CounterItems {
using namespace isc::statistics;
TEST(CounterDictionaryCreateTest, invalidCounterSize) {
// Creating counter with 0 elements will cause an isc::InvalidParameter
// exception
EXPECT_THROW(CounterDictionary counters(0), isc::InvalidParameter);
}
// This fixture is for testing CounterDictionary.
class CounterDictionaryTest : public ::testing::Test {
protected:
CounterDictionaryTest() {}
CounterDictionaryTest() : counters(NUMBER_OF_ITEMS) {
counters.addElement("test");
counters.addElement("sub.test");
}
~CounterDictionaryTest() {}
CounterDictionary counters;
};
TEST_F(CounterDictionaryTest, createCounterDictionary) {
// Create counters
CounterDictionary counters(NUMBER_OF_ITEMS);
// Add an element for this test
counters.addElement("test");
TEST_F(CounterDictionaryTest, initializeCheck) {
// Check if the all counters are initialized with 0
EXPECT_EQ(counters["test"].get(ITEM1), 0);
EXPECT_EQ(counters["test"].get(ITEM2), 0);
......@@ -49,10 +56,6 @@ TEST_F(CounterDictionaryTest, createCounterDictionary) {
}
TEST_F(CounterDictionaryTest, getElement) {
// Create counters
CounterDictionary counters(NUMBER_OF_ITEMS);
// Add an element for this test
counters.addElement("test");
// Another member function to get counters for the element
EXPECT_EQ(counters.getElement("test").get(ITEM1), 0);
EXPECT_EQ(counters.getElement("test").get(ITEM2), 0);
......@@ -60,11 +63,6 @@ TEST_F(CounterDictionaryTest, getElement) {
}
TEST_F(CounterDictionaryTest, incrementCounterItem) {
// Create counters
CounterDictionary counters(NUMBER_OF_ITEMS);
// Add elements for this test
counters.addElement("test");
counters.addElement("sub.test");
// Increment counters
counters["test"].inc(ITEM1);
counters["test"].inc(ITEM2);
......@@ -82,10 +80,6 @@ TEST_F(CounterDictionaryTest, incrementCounterItem) {
}
TEST_F(CounterDictionaryTest, deleteElement) {
// Create counters
CounterDictionary counters(NUMBER_OF_ITEMS);
// Add an element for this test
counters.addElement("test");
// Ensure the element is accessible
EXPECT_EQ(counters["test"].get(ITEM1), 0);
EXPECT_EQ(counters["test"].get(ITEM2), 0);
......@@ -99,38 +93,19 @@ TEST_F(CounterDictionaryTest, deleteElement) {
EXPECT_THROW(counters.deleteElement("test"), isc::OutOfRange);
}
TEST_F(CounterDictionaryTest, invalidCounterSize) {
// Creating counter with 0 elements will cause an isc::InvalidParameter
// exception
EXPECT_THROW(CounterDictionary counters(0), isc::InvalidParameter);
}
TEST_F(CounterDictionaryTest, invalidCounterItem) {
// Create counters
CounterDictionary counters(NUMBER_OF_ITEMS);
// Add an element for this test
counters.addElement("test");
// Incrementing out-of-bound counter will cause an isc::OutOfRange
// exception
EXPECT_THROW(counters["test"].inc(NUMBER_OF_ITEMS), isc::OutOfRange);
}
TEST_F(CounterDictionaryTest, uniqueCheck) {
// Create counters
CounterDictionary counters(NUMBER_OF_ITEMS);
// Add an element for this test
counters.addElement("test");
TEST_F(CounterDictionaryTest, uniquenessCheck) {
// Adding an element which already exists will cause an isc::OutOfRange
// exception
EXPECT_THROW(counters.addElement("test"), isc::InvalidParameter);
}
TEST_F(CounterDictionaryTest, iteratorTest) {
// Create counters
CounterDictionary counters(NUMBER_OF_ITEMS);
// Add elements for this test
counters.addElement("test");
counters.addElement("sub.test");
// Increment counters
counters["test"].inc(ITEM1);
counters["sub.test"].inc(ITEM2);
......@@ -163,17 +138,12 @@ TEST_F(CounterDictionaryTest, iteratorTest) {
FAIL() << "Unexpected iterator value";
}
}
// Check if the "test" and "sub.test" could be accessed
// Check if the "test" and "sub.test" is accessible
EXPECT_TRUE(element_test_visited);
EXPECT_TRUE(element_sub_test_visited);
}
TEST_F(CounterDictionaryTest, iteratorCopyTest) {
// Create counters
CounterDictionary counters(NUMBER_OF_ITEMS);
// Add elements for this test
counters.addElement("test");
counters.addElement("sub.test");
// Increment counters
counters["test"].inc(ITEM1);
counters["sub.test"].inc(ITEM2);
......
......@@ -28,6 +28,12 @@ enum CounterItems {
using namespace isc::statistics;
TEST(CounterCreateTest, invalidCounterSize) {
// Creating counter with 0 elements will cause an isc::InvalidParameter
// exception
EXPECT_THROW(Counter counter(0), isc::InvalidParameter);
}
// This fixture is for testing Counter.
class CounterTest : public ::testing::Test {
protected:
......@@ -69,12 +75,6 @@ TEST_F(CounterTest, incrementCounterItem) {
EXPECT_EQ(counter.get(ITEM3), 6);
}
TEST_F(CounterTest, invalidCounterSize) {
// Creating counter with 0 elements will cause an isc::InvalidParameter
// exception
EXPECT_THROW(Counter counter(0), isc::InvalidParameter);
}
TEST_F(CounterTest, invalidCounterItem) {
// Incrementing out-of-bound counter will cause an isc::OutOfRange
// exception
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment