-
Notifications
You must be signed in to change notification settings - Fork 49
/
InformationProviderImplTests.cpp
71 lines (53 loc) · 2.25 KB
/
InformationProviderImplTests.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
//
#include "common/Common.hpp"
#include "InformationProviderImpl.hpp"
#include <utility>
#include <vector>
using namespace testing;
using namespace MAT;
using namespace PAL;
namespace
{
using Callbacks = std::vector<std::pair<std::string, std::string>>;
class PropertyChangedCallbackSink : public IPropertyChangedCallback
{
Callbacks callbacks;
void OnChanged(std::string const& propertyName, std::string const& propertyValue) override
{
callbacks.emplace_back(propertyName, propertyValue);
}
public:
PropertyChangedCallbackSink() = default;
const Callbacks& GetCallbacks() { return callbacks; }
};
}
TEST(InformationProviderImplTests, ConstructionTest)
{
InformatonProviderImpl informationProvider;
}
TEST(InformationProviderImplTests, RegisterTest)
{
PropertyChangedCallbackSink callbackSink;
InformatonProviderImpl informationProvider;
int registrationCookie = informationProvider.RegisterInformationChangedCallback(&callbackSink);
informationProvider.OnChanged("PropertyName", "PropertyValue1");
// Assert that a single callback has been made, and the correct values were received
ASSERT_EQ(1u, callbackSink.GetCallbacks().size());
ASSERT_EQ((std::pair<std::string, std::string>{"PropertyName", "PropertyValue1"}), callbackSink.GetCallbacks()[0]);
informationProvider.UnRegisterInformationChangedCallback(registrationCookie);
}
TEST(InformationProviderImplTests, RegisterUnregisterTest)
{
PropertyChangedCallbackSink callbackSink;
InformatonProviderImpl informationProvider;
int registrationCookie = informationProvider.RegisterInformationChangedCallback(&callbackSink);
informationProvider.OnChanged("PropertyName", "PropertyValue1");
ASSERT_EQ(1u, callbackSink.GetCallbacks().size());
informationProvider.UnRegisterInformationChangedCallback(registrationCookie);
informationProvider.OnChanged("PropertyName", "PropertyValue2");
// After the registration has been removed only the original callback should've been received, the second notification should *not* be received.
ASSERT_EQ(1u, callbackSink.GetCallbacks().size());
}