git.fiddlerwoaroof.com
Browse code

formatting

Greg Wiley authored on 03/05/2017 18:55:01
Showing 7 changed files
... ...
@@ -41,7 +41,7 @@ dual_control initialize()
41 41
     directory directory (directory::create (unistd, pwd));
42 42
     fstreams fstreams (fstreams::create());
43 43
     tokens tokens (tokens::create (
44
-                fstreams));
44
+                       fstreams));
45 45
     validator validator (validator::create (directory, tokens));
46 46
     pam pam (pam::create());
47 47
     conversation conversation (conversation::create (pam));
... ...
@@ -24,8 +24,10 @@ public:
24 24
     {
25 25
         return pstream (new std::ifstream (file_path));
26 26
     }
27
-    postream open_ofstream (const std::string &file_path, std::ios_base::open_mode mode) const override {
28
-        return postream(new std::ofstream(file_path, mode));
27
+    postream open_ofstream (const std::string &file_path,
28
+                            std::ios_base::open_mode mode) const override
29
+    {
30
+        return postream (new std::ofstream (file_path, mode));
29 31
     }
30 32
 
31 33
 };
... ...
@@ -26,8 +26,10 @@ public:
26 26
     {
27 27
         return pstream (new std::istringstream (""));
28 28
     }
29
-    virtual postream open_ofstream(const std::string &file_path, std::ios_base::openmode mode) const {
30
-        return postream(new std::ostringstream(""));
29
+    virtual postream open_ofstream (const std::string &file_path,
30
+                                    std::ios_base::openmode mode) const
31
+    {
32
+        return postream (new std::ostringstream (""));
31 33
     }
32 34
 };
33 35
 
... ...
@@ -46,7 +48,8 @@ public:
46 48
     {
47 49
         return delegate_->open_fstream (file_path);
48 50
     }
49
-    postream open_ofstream (const std::string &file_path, std::ios_base::openmode mode) const
51
+    postream open_ofstream (const std::string &file_path,
52
+                            std::ios_base::openmode mode) const
50 53
     {
51 54
         return delegate_->open_ofstream (file_path, mode);
52 55
     }
... ...
@@ -28,8 +28,9 @@ private:
28 28
     fstreams fstreams_;
29 29
     token_generator generate_token_;
30 30
 public:
31
-    tokens_impl (const fstreams &fstreams, const token_generator &generate_token) :
32
-        generate_token_(generate_token),
31
+    tokens_impl (const fstreams &fstreams,
32
+                 const token_generator &generate_token) :
33
+        generate_token_ (generate_token),
33 34
         fstreams_ (fstreams) {}
34 35
     std::string token (const user &user) const override
35 36
     {
... ...
@@ -45,17 +46,20 @@ public:
45 46
         stream->getline (line.data(), line.size());
46 47
         return std::string (line.data());
47 48
     }
48
-    void create(const user &user) const override {
49
-        std::string generated_token(generate_token_());
50
-        std::string file_path(user.home_directory() + "/.dual_control");
51
-        fstreams::postream stream(fstreams_.open_ofstream(file_path, std::ios_base::trunc));
49
+    void create (const user &user) const override
50
+    {
51
+        std::string generated_token (generate_token_());
52
+        std::string file_path (user.home_directory() + "/.dual_control");
53
+        fstreams::postream stream (fstreams_.open_ofstream (file_path,
54
+                                   std::ios_base::trunc));
52 55
         *stream << generated_token << std::endl;
53 56
     }
54 57
 };
55 58
 }
56
-tokens tokens::create (const fstreams &fstreams, const tokens_impl::token_generator &generate_token)
59
+tokens tokens::create (const fstreams &fstreams,
60
+                       const tokens_impl::token_generator &generate_token)
57 61
 {
58 62
     return tokens (tokens::delegate
59
-                                (new tokens_impl (fstreams, generate_token)));
63
+                   (new tokens_impl (fstreams, generate_token)));
60 64
 }
61 65
 
... ...
@@ -28,7 +28,7 @@ public:
28 28
     {
29 29
         return "";
30 30
     }
31
-    virtual void create(const user &user) const {}
31
+    virtual void create (const user &user) const {}
32 32
 };
33 33
 
34 34
 class tokens
... ...
@@ -46,10 +46,12 @@ public:
46 46
     {
47 47
         return delegate_->token (user);
48 48
     }
49
-    void create(const user &user) const {
50
-        return delegate_->create(user);
49
+    void create (const user &user) const
50
+    {
51
+        return delegate_->create (user);
51 52
     }
52
-    static tokens create (const fstreams &fstreams, const tokens_ifc::token_generator &generate_token);
53
+    static tokens create (const fstreams &fstreams,
54
+                          const tokens_ifc::token_generator &generate_token);
53 55
 };
54 56
 
55 57
 #endif
... ...
@@ -38,22 +38,27 @@ public:
38 38
     }
39 39
 };
40 40
 
41
-class mock_write_fstreams: public fstreams_ifc {
42
-    private:
43
-        mutable std::string captured_filename_;
44
-        mutable std::shared_ptr<std::ostringstream> capture_stream_;
45
-    public:
46
-        postream open_ofstream (const std::string &file_path, std::ios_base::open_mode mode) const override {
47
-            captured_filename_ = file_path;
48
-            capture_stream_ = std::make_shared<std::ostringstream>();
49
-            return capture_stream_;
50
-        }
51
-        std::string captured_filename() {
52
-            return captured_filename_;
53
-        }
54
-        std::string captured_written() {
55
-            return capture_stream_->str();
56
-        }
41
+class mock_write_fstreams: public fstreams_ifc
42
+{
43
+private:
44
+    mutable std::string captured_filename_;
45
+    mutable std::shared_ptr<std::ostringstream> capture_stream_;
46
+public:
47
+    postream open_ofstream (const std::string &file_path,
48
+                            std::ios_base::open_mode mode) const override
49
+    {
50
+        captured_filename_ = file_path;
51
+        capture_stream_ = std::make_shared<std::ostringstream>();
52
+        return capture_stream_;
53
+    }
54
+    std::string captured_filename()
55
+    {
56
+        return captured_filename_;
57
+    }
58
+    std::string captured_written()
59
+    {
60
+        return capture_stream_->str();
61
+    }
57 62
 };
58 63
 
59 64
 class fake_fstreams : public fstreams_ifc
... ...
@@ -90,7 +95,7 @@ int reads_from_the_right_file ()
90 95
     //file_reader test_file_reader (file_reader::delegate (new fake_file_reader));
91 96
     user test_user (user::delegate (new fake_user (home_directory)));
92 97
     tokens supplier (tokens::create (
93
-                                      test_streams,[]{return"";}));
98
+                         test_streams,[] {return"";}));
94 99
 
95 100
     //when
96 101
     std::string actual = supplier.token (test_user);
... ...
@@ -110,7 +115,7 @@ int returns_empty_string_if_file_open_fail()
110 115
                            "654321")));
111 116
     user test_user (user::delegate (new fake_user (home_directory)));
112 117
     tokens supplier (tokens::create (
113
-                                      test_streams, []{return "";}));
118
+                         test_streams, [] {return "";}));
114 119
 
115 120
     //when
116 121
     std::string actual = supplier.token (test_user);
... ...
@@ -120,29 +125,31 @@ int returns_empty_string_if_file_open_fail()
120 125
     succeed();
121 126
 }
122 127
 
123
-int writes_the_token () {
128
+int writes_the_token ()
129
+{
124 130
     // given
125
-    std::string home_directory("/somedir");
126
-    user test_user(user::delegate(new fake_user(home_directory)));
127
-    mock_write_fstreams *mockfs(new mock_write_fstreams);
128
-    fstreams test_streams{fstreams::delegate(mockfs)};
129
-    std::string token("token");
130
-    tokens tokens(tokens::create(test_streams, [&]{return token;}));
131
+    std::string home_directory ("/somedir");
132
+    user test_user (user::delegate (new fake_user (home_directory)));
133
+    mock_write_fstreams *mockfs (new mock_write_fstreams);
134
+    fstreams test_streams{fstreams::delegate (mockfs)};
135
+    std::string token ("token");
136
+    tokens tokens (tokens::create (test_streams, [&] {return token;}));
131 137
 
132 138
     //when
133
-    tokens.create(test_user);
139
+    tokens.create (test_user);
134 140
 
135
-   // then
141
+    // then
136 142
     std::ostringstream temp;
137 143
     temp << token << std::endl;
138 144
     std::string expected_written = temp.str();
139
-    std::string expected_filename(home_directory + "/.dual_control");
140
-    check(mockfs->captured_filename() == expected_filename, "filename does not match");
141
-    check(mockfs->captured_written() == expected_written, "token does not match");
142
-   succeed();
145
+    std::string expected_filename (home_directory + "/.dual_control");
146
+    check (mockfs->captured_filename() == expected_filename,
147
+           "filename does not match");
148
+    check (mockfs->captured_written() == expected_written,
149
+           "token does not match");
150
+    succeed();
143 151
 }
144 152
 
145
-
146 153
 int run_tests()
147 154
 {
148 155
     test (reads_from_the_right_file);
... ...
@@ -64,7 +64,7 @@ bool validator_validates()
64 64
     // given
65 65
     std::string token = "token";
66 66
     tokens tokens (share (new
67
-            fake_tokens (token)));
67
+                          fake_tokens (token)));
68 68
     std::string user_name = "msmith";
69 69
     directory directory (share (new fake_directory (user_name)));
70 70
     validator validator = validator::create (directory, tokens);
... ...
@@ -83,7 +83,7 @@ bool validator_fails_unknown_user()
83 83
     // given
84 84
     std::string token = "token";
85 85
     tokens tokens (share (new
86
-            fake_tokens));
86
+                          fake_tokens));
87 87
     directory directory (share (new fake_directory));
88 88
     validator validator = validator::create (directory, tokens);
89 89
 
... ...
@@ -100,7 +100,7 @@ bool validator_fails_incorrect_token()
100 100
 
101 101
     // given
102 102
     tokens tokens (share (new
103
-            fake_tokens));
103
+                          fake_tokens));
104 104
     std::string user_name = "msmith";
105 105
     directory directory (share (new fake_directory (user_name)));
106 106
     validator validator = validator::create (directory, tokens);
... ...
@@ -121,7 +121,7 @@ bool validator_fails_with_own_token()
121 121
     std::string authorizer_token ("token");
122 122
     directory directory (share (new fake_directory (authorizer_user_name)));
123 123
     tokens tokens (share (new
124
-            fake_tokens (authorizer_token)));
124
+                          fake_tokens (authorizer_token)));
125 125
     validator validator = validator::create (directory, tokens);
126 126
 
127 127
     // when
... ...
@@ -142,7 +142,7 @@ bool validator_fails_with_unknown_requester()
142 142
     std::string authorizer_token ("token");
143 143
     directory directory (share (new fake_directory (authorizer_user_name)));
144 144
     tokens tokens (share (new
145
-            fake_tokens (authorizer_token)));
145
+                          fake_tokens (authorizer_token)));
146 146
     validator validator = validator::create (directory, tokens);
147 147
 
148 148
     // when