git.fiddlerwoaroof.com
Greg Wiley authored on 18/04/2017 23:23:56
Showing 1 changed files
... ...
@@ -8,6 +8,12 @@
8 8
 #include "test_util.h"
9 9
 
10 10
 
11
+template<class T>
12
+std::shared_ptr<T> share(T* t) {
13
+  return std::shared_ptr<T>(t);
14
+}
15
+
16
+
11 17
 class mock_logger : public logger_ifc {
12 18
     private:
13 19
         int result_;
... ...
@@ -74,8 +80,8 @@ int authenticate_validates_with_received_token() {
74 80
     dual_control_configuration configuration;
75 81
     std::string user("user");
76 82
     std::string token("token");
77
-    configuration.validator = validator(std::shared_ptr<validator_ifc>(new fake_validator(user, token)));
78
-    configuration.conversations = conversations(std::shared_ptr<conversations_ifc>(new fake_conversations(user, token)));
83
+    configuration.validator = validator(share(new fake_validator(user, token)));
84
+    configuration.conversations = conversations(share(new fake_conversations(user, token)));
79 85
     dual_control dc(create_dual_control(configuration));
80 86
     pam_handle_t *handle(0);
81 87
     std::vector<const std::string> arguments;
... ...
@@ -92,8 +98,8 @@ int authenticate_fails_with_wrong_user() {
92 98
     // given
93 99
     dual_control_configuration configuration;
94 100
     std::string token("token");
95
-    configuration.validator = validator(std::shared_ptr<validator_ifc>(new fake_validator("user", token)));
96
-    configuration.conversations = conversations(std::shared_ptr<conversations_ifc>(new fake_conversations("wrong user", token)));
101
+    configuration.validator = validator(share(new fake_validator("user", token)));
102
+    configuration.conversations = conversations(share(new fake_conversations("wrong user", token)));
97 103
     dual_control dc(create_dual_control(configuration));
98 104
     pam_handle_t *handle(0);
99 105
     std::vector<const std::string> arguments;
... ...
@@ -110,8 +116,8 @@ int authenticate_fails_with_wrong_token() {
110 116
     // given
111 117
     dual_control_configuration configuration;
112 118
     std::string user("user");
113
-    configuration.validator = validator(std::shared_ptr<validator_ifc>(new fake_validator(user, "token")));
114
-    configuration.conversations = conversations(std::shared_ptr<conversations_ifc>(new fake_conversations(user, "wrong token")));
119
+    configuration.validator = validator(share(new fake_validator(user, "token")));
120
+    configuration.conversations = conversations(share(new fake_conversations(user, "wrong token")));
115 121
     dual_control dc(create_dual_control(configuration));
116 122
     pam_handle_t *handle(0);
117 123
     std::vector<const std::string> arguments;
... ...
@@ -129,10 +135,10 @@ int logs_authentication() {
129 135
     dual_control_configuration configuration;
130 136
     std::string user("user");
131 137
     std::string token("token");
132
-    configuration.validator = validator(std::shared_ptr<validator_ifc>(new fake_validator(user, token)));
133
-    configuration.conversations = conversations(std::shared_ptr<conversations_ifc>(new fake_conversations(user, token)));
138
+    configuration.validator = validator(share(new fake_validator(user, token)));
139
+    configuration.conversations = conversations(share(new fake_conversations(user, token)));
134 140
     mock_logger *test_logger = new mock_logger;
135
-    configuration.logger = logger(std::shared_ptr<logger_ifc>(test_logger));
141
+    configuration.logger = logger(share(test_logger));
136 142
     dual_control dc(create_dual_control(configuration));
137 143
     pam_handle_t *handle(0);
138 144
     std::vector<const std::string> arguments;
... ...
@@ -152,10 +158,10 @@ int logs_authentication_failure() {
152 158
     dual_control_configuration configuration;
153 159
     std::string user("user");
154 160
     std::string token("token");
155
-    configuration.validator = validator(std::shared_ptr<validator_ifc>(new fake_validator(user, "not the received token")));
156
-    configuration.conversations = conversations(std::shared_ptr<conversations_ifc>(new fake_conversations(user, token)));
161
+    configuration.validator = validator(share(new fake_validator(user, "not the received token")));
162
+    configuration.conversations = conversations(share(new fake_conversations(user, token)));
157 163
     mock_logger *test_logger = new mock_logger;
158
-    configuration.logger = logger(std::shared_ptr<logger_ifc>(test_logger));
164
+    configuration.logger = logger(share(test_logger));
159 165
     dual_control dc(create_dual_control(configuration));
160 166
     pam_handle_t *handle(0);
161 167
     std::vector<const std::string> arguments;