|
|
@@ -0,0 +1,73 @@
|
|
|
+//
|
|
|
+// fps_counter_test.cxx
|
|
|
+// engine-test
|
|
|
+//
|
|
|
+// Created by Sam Jaffe on 7/7/19.
|
|
|
+// Copyright © 2019 Sam Jaffe. All rights reserved.
|
|
|
+//
|
|
|
+
|
|
|
+#include <gmock/gmock.h>
|
|
|
+
|
|
|
+#include "game/engine/fps_counter.hpp"
|
|
|
+#include "game/engine/text_engine.hpp"
|
|
|
+
|
|
|
+#include "mock_renderer.h"
|
|
|
+
|
|
|
+#ifdef __APPLE__
|
|
|
+namespace env { namespace detail {
|
|
|
+ extern void bundle(std::string const &);
|
|
|
+}}
|
|
|
+#endif
|
|
|
+
|
|
|
+using testing::IsEmpty;
|
|
|
+using testing::SizeIs;
|
|
|
+
|
|
|
+struct FpsCounterTest : testing::Test {
|
|
|
+ void SetUp() override;
|
|
|
+ void TearDown() override;
|
|
|
+ std::shared_ptr<graphics::manager> manager;
|
|
|
+ std::shared_ptr<engine::text_engine> engine;
|
|
|
+};
|
|
|
+
|
|
|
+void FpsCounterTest::SetUp() {
|
|
|
+#ifdef __APPLE__
|
|
|
+ env::detail::bundle("leumasjaffe.engine-test");
|
|
|
+#endif
|
|
|
+ manager.reset(new stub_manager_impl);
|
|
|
+ engine.reset(new engine::text_engine("font", manager));
|
|
|
+}
|
|
|
+
|
|
|
+void FpsCounterTest::TearDown() {
|
|
|
+ engine.reset();
|
|
|
+ manager.reset();
|
|
|
+}
|
|
|
+
|
|
|
+TEST_F(FpsCounterTest, CanConstructCtrNoExcept) {
|
|
|
+ EXPECT_NO_THROW(engine::fps_counter(engine, 5));
|
|
|
+}
|
|
|
+
|
|
|
+TEST_F(FpsCounterTest, CanFrameNoExcept) {
|
|
|
+ engine::fps_counter counter(engine, 5);
|
|
|
+ env::clock::duration ms_100{100000000LL};
|
|
|
+ EXPECT_NO_THROW(counter.set_frame_step(ms_100));
|
|
|
+}
|
|
|
+
|
|
|
+// TODO (sjaffe): Give ability to specifiy change_after_ in ctor?
|
|
|
+TEST_F(FpsCounterTest, NoGlyphsUntilCrossesChangeThresh) {
|
|
|
+ engine::fps_counter counter(engine, 5);
|
|
|
+ env::clock::duration ms_100{100000000LL};
|
|
|
+ EXPECT_THAT(counter.glyphs(), IsEmpty());
|
|
|
+ counter.set_frame_step(ms_100);
|
|
|
+ EXPECT_THAT(counter.glyphs(), IsEmpty());
|
|
|
+}
|
|
|
+
|
|
|
+// TODO (sjaffe): Test different precisions
|
|
|
+// TODO (sjaffe): Test <10 fps and >=100 fps
|
|
|
+TEST_F(FpsCounterTest, ProducesEnoughDigitsForPrecision) {
|
|
|
+ engine::fps_counter counter(engine, 5);
|
|
|
+ env::clock::duration ms_100{100000000LL};
|
|
|
+ for (int i = 0; i < 10; ++i) {
|
|
|
+ counter.set_frame_step(ms_100);
|
|
|
+ }
|
|
|
+ EXPECT_THAT(counter.glyphs(), SizeIs(8));
|
|
|
+}
|