Advertisement
Guest User

Untitled

a guest
Mar 11th, 2012
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1. #include "time_keeper.h"
  2.  
  3. #include <gtest/gtest.h>
  4. #include <gmock/gmock.h>
  5.  
  6. #include "mocks/glfw_api_mock.h"
  7.  
  8. using ::testing::Return;
  9. using ::testing::_;
  10.  
  11. class TimeKeeperTest : public ::testing::Test {
  12.   protected:
  13.     TimeKeeper* time_keeper;
  14.     GlfwApiMock glfw_api_mock;
  15.  
  16.     virtual void SetUp() {
  17.       time_keeper = new TimeKeeper(&glfw_api_mock);
  18.     }
  19.     virtual void TearDown() {
  20.     }
  21. };
  22.  
  23. TEST_F(TimeKeeperTest, returnDelta) {
  24.   ASSERT_LE(0, time_keeper->getDelta());
  25. }
  26.  
  27. TEST_F(TimeKeeperTest, returnDifferentDeltas) {
  28.   EXPECT_CALL(glfw_api_mock, glfwGetTime()).WillOnce(Return(10));
  29.  
  30.   double first_delta;
  31.   double second_delta;
  32.  
  33.   first_delta = time_keeper->getDelta();
  34.   time_keeper->calculate();
  35.   second_delta = time_keeper->getDelta();
  36.   ASSERT_LT(first_delta, second_delta);
  37. }
  38.  
  39. TEST_F(TimeKeeperTest, resetDelta) {
  40.   EXPECT_CALL(glfw_api_mock, glfwGetTime()).WillRepeatedly(Return(10));
  41.  
  42.   time_keeper->calculate();
  43.   ASSERT_LT(0, time_keeper->getDelta());
  44.   time_keeper->reset();
  45.   ASSERT_EQ(0, time_keeper->getDelta());
  46. }
  47.  
  48. TEST_F(TimeKeeperTest, returnCorrectDeltaAfterReset) {
  49.   EXPECT_CALL(glfw_api_mock, glfwGetTime()).WillOnce(Return(10)).WillOnce(
  50.       Return(20)).WillOnce(Return(40));
  51.  
  52.   time_keeper->calculate();
  53.   time_keeper->reset();
  54.   time_keeper->calculate();
  55.   ASSERT_EQ(20, time_keeper->getDelta());
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement