• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2016 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // Observer_unittest:
7 //   Unit tests for Observers and related classes.
8 
9 #include <gtest/gtest.h>
10 
11 #include "libANGLE/Observer.h"
12 
13 using namespace angle;
14 using namespace testing;
15 
16 namespace
17 {
18 
19 struct ObserverClass : public ObserverInterface
20 {
onSubjectStateChange__anon5c040caa0111::ObserverClass21     void onSubjectStateChange(SubjectIndex index, SubjectMessage message) override
22     {
23         wasNotified = true;
24     }
25     bool wasNotified = false;
26 };
27 
28 // Test that Observer/Subject state change notifications work.
TEST(ObserverTest,BasicUsage)29 TEST(ObserverTest, BasicUsage)
30 {
31     Subject subject;
32     ObserverClass observer;
33     ObserverBinding binding(&observer, 0u);
34 
35     binding.bind(&subject);
36     ASSERT_FALSE(observer.wasNotified);
37     subject.onStateChange(SubjectMessage::SubjectChanged);
38     ASSERT_TRUE(observer.wasNotified);
39 }
40 
41 }  // anonymous namespace
42