git.fiddlerwoaroof.com
Browse code

formatting

jbalcita authored on 03/05/2017 23:53:10
Showing 10 changed files
... ...
@@ -41,7 +41,7 @@ public:
41 41
     conversation (const std::shared_ptr<conversation_ifc> &delegate) :
42 42
         delegate_ (delegate) {}
43 43
     conversation() : conversation (std::make_shared<conversation_ifc>()
44
-                                       ) {}
44
+                                      ) {}
45 45
     conversation_result initiate (const pam_request &request)
46 46
     {
47 47
         return delegate_->initiate (request);
... ...
@@ -1,11 +1,24 @@
1
+/* Copyright (C) CJ Affiliate
2
+ *
3
+ * You may use, distribute and modify this code under  the
4
+ * terms of the  GNU General Public License  version 2  or
5
+ * later.
6
+ *
7
+ * You should have received a copy of the license with this
8
+ * file. If not, you will find a copy in the "LICENSE" file
9
+ * at https://github.com/cjdev/dual-control.
10
+ */
11
+
1 12
 #include <string>
2 13
 #include <iostream>
3 14
 
4 15
 #include "installer.h"
5 16
 
6
-int main(int argc, char *argv[]) {
17
+int main (int argc, char *argv[])
18
+{
7 19
     installer tool;
8 20
     std::string generated_token = tool.install_token();
9 21
     std::cout << generated_token << std::endl;
10 22
     return 0;
11 23
 }
24
+
... ...
@@ -1,3 +1,14 @@
1
+/* Copyright (C) CJ Affiliate
2
+ *
3
+ * You may use, distribute and modify this code under  the
4
+ * terms of the  GNU General Public License  version 2  or
5
+ * later.
6
+ *
7
+ * You should have received a copy of the license with this
8
+ * file. If not, you will find a copy in the "LICENSE" file
9
+ * at https://github.com/cjdev/dual-control.
10
+ */
11
+
1 12
 #ifndef GENERATOR_H_
2 13
 #define GENERATOR_H_
3 14
 
... ...
@@ -6,8 +17,9 @@
6 17
 
7 18
 using generator = std::function<std::string()>;
8 19
 
9
-inline generator make_generator() {
10
-    return [] {return std::string("234567");};
20
+inline generator make_generator()
21
+{
22
+    return [] {return std::string ("234567");};
11 23
 }
12 24
 
13 25
 #endif
... ...
@@ -1,29 +1,43 @@
1
+/* Copyright (C) CJ Affiliate
2
+ *
3
+ * You may use, distribute and modify this code under  the
4
+ * terms of the  GNU General Public License  version 2  or
5
+ * later.
6
+ *
7
+ * You should have received a copy of the license with this
8
+ * file. If not, you will find a copy in the "LICENSE" file
9
+ * at https://github.com/cjdev/dual-control.
10
+ */
11
+
1 12
 #include <algorithm>
2 13
 
3 14
 #include "generator.h"
4 15
 #include "test_util.h"
5 16
 
6
-int six_digits()  {
7
-   // given
8
-   generator generator = make_generator();
9
-
10
-  // when
11
-  auto actual = generator();
17
+int six_digits()
18
+{
19
+    // given
20
+    generator generator = make_generator();
12 21
 
22
+    // when
23
+    auto actual = generator();
13 24
 
14
-  // then
15
-  check(actual.size() == 6, "size is wrong");
16
-  check(std::all_of(actual.begin(), actual.end(), [](char c){ return c >= '0' && c <= '9';}), "not just digits");
17
-  succeed();
25
+    // then
26
+    check (actual.size() == 6, "size is wrong");
27
+    check (std::all_of (actual.begin(), actual.end(), [] (char c) {
28
+        return c >= '0' && c <= '9';
29
+    }), "not just digits");
30
+    succeed();
18 31
 }
19 32
 
20
-
21
-int run_tests() {
22
-    test(six_digits);
33
+int run_tests()
34
+{
35
+    test (six_digits);
23 36
     succeed();
24 37
 }
25 38
 
26
-int main(int argc, char *argv[]) {
39
+int main (int argc, char *argv[])
40
+{
27 41
     return !run_tests();
28 42
 }
29 43
 
... ...
@@ -1,3 +1,14 @@
1
+/* Copyright (C) CJ Affiliate
2
+ *
3
+ * You may use, distribute and modify this code under  the
4
+ * terms of the  GNU General Public License  version 2  or
5
+ * later.
6
+ *
7
+ * You should have received a copy of the license with this
8
+ * file. If not, you will find a copy in the "LICENSE" file
9
+ * at https://github.com/cjdev/dual-control.
10
+ */
11
+
1 12
 #include <string>
2 13
 #include <vector>
3 14
 
... ...
@@ -6,43 +17,50 @@
6 17
 #include "sys_unistd.h"
7 18
 #include "user.h"
8 19
 
9
-namespace {
10
-
11
-class impl : public installer_ifc {
12
-    private:
13
-        tokens tokens_;
14
-        unistd unistd_;
15
-        directory directory_;
16
-        generator generator_;
17
-    public:
18
-        impl(const tokens &tokens, const unistd &unistd,
19
-            const directory &directory, const installer_ifc::generator &generator) :
20
-            tokens_(tokens), unistd_(unistd), directory_(directory), generator_(generator) {}
21
-        std::string install_token() const override {
22
-            const char *c_user_name = unistd_.getlogin();
23
-            if (c_user_name == nullptr) {
24
-                return "";
25
-            }
26
-
27
-            std::string user_name = c_user_name;
28
-
29
-            auto found_user = directory_.find_user(user_name);
30
-            if (found_user.empty()) {
31
-                return "";
32
-            }
33
-
34
-            user user(found_user[0]);
35
-            std::string token(generator_());
36
-            tokens_.save(user, token);
37
-            return token;
20
+namespace
21
+{
22
+
23
+class impl : public installer_ifc
24
+{
25
+private:
26
+    tokens tokens_;
27
+    unistd unistd_;
28
+    directory directory_;
29
+    generator generator_;
30
+public:
31
+    impl (const tokens &tokens, const unistd &unistd,
32
+          const directory &directory, const installer_ifc::generator &generator) :
33
+        tokens_ (tokens), unistd_ (unistd), directory_ (directory),
34
+        generator_ (generator) {}
35
+    std::string install_token() const override
36
+    {
37
+        const char *c_user_name = unistd_.getlogin();
38
+
39
+        if (c_user_name == nullptr) {
40
+            return "";
38 41
         }
42
+
43
+        std::string user_name = c_user_name;
44
+
45
+        auto found_user = directory_.find_user (user_name);
46
+
47
+        if (found_user.empty()) {
48
+            return "";
49
+        }
50
+
51
+        user user (found_user[0]);
52
+        std::string token (generator_());
53
+        tokens_.save (user, token);
54
+        return token;
55
+    }
39 56
 };
40 57
 
41 58
 }
42 59
 
43
-
44
-installer installer::create(const tokens &tokens, const unistd &unistd,
45
-        const directory &directory, const installer_ifc::generator &generator) {
46
-    return installer(std::make_shared<impl>(tokens, unistd, directory, generator));
60
+installer installer::create (const tokens &tokens, const unistd &unistd,
61
+                             const directory &directory, const installer_ifc::generator &generator)
62
+{
63
+    return installer (std::make_shared<impl> (tokens, unistd, directory,
64
+                      generator));
47 65
 }
48 66
 
... ...
@@ -1,3 +1,14 @@
1
+/* Copyright (C) CJ Affiliate
2
+ *
3
+ * You may use, distribute and modify this code under  the
4
+ * terms of the  GNU General Public License  version 2  or
5
+ * later.
6
+ *
7
+ * You should have received a copy of the license with this
8
+ * file. If not, you will find a copy in the "LICENSE" file
9
+ * at https://github.com/cjdev/dual-control.
10
+ */
11
+
1 12
 #ifndef INSTALLER_H_
2 13
 #define INSTALLER_H_
3 14
 
... ...
@@ -9,30 +20,32 @@
9 20
 #include "sys_unistd.h"
10 21
 #include "user.h"
11 22
 
12
-
13
-class installer_ifc {
14
-    public:
15
-        using generator = std::function<std::string()>;
16
-        virtual std::string install_token() const {
17
-            return "123456";
18
-        }
23
+class installer_ifc
24
+{
25
+public:
26
+    using generator = std::function<std::string()>;
27
+    virtual std::string install_token() const
28
+    {
29
+        return "123456";
30
+    }
19 31
 };
20 32
 
21
-class installer {
22
-    public:
23
-        using delegate = std::shared_ptr<installer_ifc>;
24
-    private:
25
-        delegate delegate_;
26
-    public:
27
-        installer(const delegate &delegate = std::make_shared<installer_ifc>()) : delegate_(delegate) {}
28
-        std::string install_token() const {
29
-            return delegate_->install_token();
30
-        }
31
-        static installer create(const tokens &tokens, const unistd &unistd,
32
-            const directory &directory, const installer_ifc::generator &generator);
33
+class installer
34
+{
35
+public:
36
+    using delegate = std::shared_ptr<installer_ifc>;
37
+private:
38
+    delegate delegate_;
39
+public:
40
+    installer (const delegate &delegate = std::make_shared<installer_ifc>()) :
41
+        delegate_ (delegate) {}
42
+    std::string install_token() const
43
+    {
44
+        return delegate_->install_token();
45
+    }
46
+    static installer create (const tokens &tokens, const unistd &unistd,
47
+                             const directory &directory, const installer_ifc::generator &generator);
33 48
 };
34 49
 
35
-
36
-
37
-
38 50
 #endif
51
+
... ...
@@ -1,3 +1,14 @@
1
+/* Copyright (C) CJ Affiliate
2
+ *
3
+ * You may use, distribute and modify this code under  the
4
+ * terms of the  GNU General Public License  version 2  or
5
+ * later.
6
+ *
7
+ * You should have received a copy of the license with this
8
+ * file. If not, you will find a copy in the "LICENSE" file
9
+ * at https://github.com/cjdev/dual-control.
10
+ */
11
+
1 12
 #include <functional>
2 13
 #include <memory>
3 14
 #include <string>
... ...
@@ -8,118 +19,138 @@
8 19
 #include "token.h"
9 20
 #include "test_util.h"
10 21
 
11
-class mock_tokens : public tokens_ifc {
12
-    public:
13
-        mutable std::string captured_token;
14
-        void save (const user &user, const std::string &token) const override {
15
-            captured_token = token;
16
-        }
22
+class mock_tokens : public tokens_ifc
23
+{
24
+public:
25
+    mutable std::string captured_token;
26
+    void save (const user &user, const std::string &token) const override
27
+    {
28
+        captured_token = token;
29
+    }
17 30
 };
18 31
 
19
-class fake_unistd : public unistd_ifc {
20
-    private:
21
-        std::string user_name_;
22
-    public:
23
-        fake_unistd(const std::string &user_name) : user_name_(user_name) {}
24
-        const char *getlogin() const override {
25
-            return user_name_.c_str();
26
-        }
32
+class fake_unistd : public unistd_ifc
33
+{
34
+private:
35
+    std::string user_name_;
36
+public:
37
+    fake_unistd (const std::string &user_name) : user_name_ (user_name) {}
38
+    const char *getlogin() const override
39
+    {
40
+        return user_name_.c_str();
41
+    }
27 42
 };
28 43
 
29
-class fail_unistd : public unistd_ifc {
30
-    public:
31
-        const char *getlogin() const override {
32
-            return nullptr;
33
-        }
44
+class fail_unistd : public unistd_ifc
45
+{
46
+public:
47
+    const char *getlogin() const override
48
+    {
49
+        return nullptr;
50
+    }
34 51
 };
35 52
 
36
-class fake_directory : public directory_ifc {
37
-    private:
38
-        std::string expected_user_name_;
39
-    public:
40
-        fake_directory(const std::string &expected_user_name) : expected_user_name_(expected_user_name) {
41
-        }
42
-        std::vector<user> find_user (const std::string &user_name) const override {
43
-            std::vector<user> rval;
44
-            if (user_name == expected_user_name_) {
45
-                rval.push_back(user());
46
-            }
47
-            return rval;
53
+class fake_directory : public directory_ifc
54
+{
55
+private:
56
+    std::string expected_user_name_;
57
+public:
58
+    fake_directory (const std::string &expected_user_name) :
59
+        expected_user_name_ (expected_user_name)
60
+    {
61
+    }
62
+    std::vector<user> find_user (const std::string &user_name) const override
63
+    {
64
+        std::vector<user> rval;
65
+
66
+        if (user_name == expected_user_name_) {
67
+            rval.push_back (user());
48 68
         }
49 69
 
70
+        return rval;
71
+    }
72
+
50 73
 };
51 74
 
52
-int installs_token() {
75
+int installs_token()
76
+{
53 77
     //given
54
-    std::string user_name("user");
55
-    std::string token("token");
78
+    std::string user_name ("user");
79
+    std::string token ("token");
56 80
     auto  test_tokens = std::make_shared<mock_tokens>();
57 81
     tokens tokens{test_tokens};
58
-    unistd unistd(std::make_shared<fake_unistd>(user_name));
59
-    directory directory(std::make_shared<fake_directory>(user_name));
82
+    unistd unistd (std::make_shared<fake_unistd> (user_name));
83
+    directory directory (std::make_shared<fake_directory> (user_name));
60 84
     installer_ifc::generator generator = [&] { return token; };
61 85
 
62
-    installer installer = installer::create (tokens, unistd, directory, generator);
86
+    installer installer = installer::create (tokens, unistd, directory,
87
+                          generator);
63 88
 
64 89
     //when
65 90
     std::string result = installer.install_token();
66 91
 
67 92
     //then
68
-    check(test_tokens->captured_token == token, "installed wrong token");
69
-    check(result == token, "installer returned wrong token");
93
+    check (test_tokens->captured_token == token, "installed wrong token");
94
+    check (result == token, "installer returned wrong token");
70 95
     succeed();
71 96
 }
72 97
 
73
-int unistd_does_not_find_user_name() {
98
+int unistd_does_not_find_user_name()
99
+{
74 100
     //given
75
-    std::string user_name("user");
76
-    std::string token("token");
101
+    std::string user_name ("user");
102
+    std::string token ("token");
77 103
     auto  test_tokens = std::make_shared<mock_tokens>();
78 104
     tokens tokens{test_tokens};
79
-    unistd unistd(std::make_shared<fail_unistd>());
80
-    directory directory(std::make_shared<fake_directory>(user_name));
105
+    unistd unistd (std::make_shared<fail_unistd>());
106
+    directory directory (std::make_shared<fake_directory> (user_name));
81 107
     installer_ifc::generator generator = [&] { return token; };
82 108
 
83
-    installer installer = installer::create (tokens, unistd, directory, generator);
84
-
109
+    installer installer = installer::create (tokens, unistd, directory,
110
+                          generator);
85 111
 
86 112
     //when
87 113
     auto returned = installer.install_token();
88 114
 
89 115
     //then
90
-    check(test_tokens->captured_token == "", "should not have installed a token");
91
-    check(returned == "", "did not return empty token");
116
+    check (test_tokens->captured_token == "",
117
+           "should not have installed a token");
118
+    check (returned == "", "did not return empty token");
92 119
     succeed();
93 120
 }
94 121
 
95
-int directory_finds_no_user_info() {
96
-    std::string user_name("user");
97
-    std::string token("token");
122
+int directory_finds_no_user_info()
123
+{
124
+    std::string user_name ("user");
125
+    std::string token ("token");
98 126
     auto  test_tokens = std::make_shared<mock_tokens>();
99 127
     tokens tokens{test_tokens};
100
-    unistd unistd(std::make_shared<fake_unistd>(user_name));
101
-    directory directory(std::make_shared<fake_directory>("not the user"));
128
+    unistd unistd (std::make_shared<fake_unistd> (user_name));
129
+    directory directory (std::make_shared<fake_directory> ("not the user"));
102 130
     installer_ifc::generator generator = [&] { return token; };
103 131
 
104
-    installer installer = installer::create (tokens, unistd, directory, generator);
132
+    installer installer = installer::create (tokens, unistd, directory,
133
+                          generator);
105 134
 
106 135
     //when
107 136
     auto returned = installer.install_token();
108 137
 
109 138
     //then
110
-    check(test_tokens->captured_token == "", "installed wrong token");
111
-    check(returned == "", "did not return empty token");
139
+    check (test_tokens->captured_token == "", "installed wrong token");
140
+    check (returned == "", "did not return empty token");
112 141
     succeed();
113 142
 }
114 143
 
115
-int run_tests() {
116
-    test(installs_token);
117
-    test(unistd_does_not_find_user_name);
118
-    test(directory_finds_no_user_info);
144
+int run_tests()
145
+{
146
+    test (installs_token);
147
+    test (unistd_does_not_find_user_name);
148
+    test (directory_finds_no_user_info);
119 149
     succeed();
120 150
 }
121 151
 
122
-int main(int argc, char *argv[]) {
152
+int main (int argc, char *argv[])
153
+{
123 154
     return !run_tests();
124 155
 }
125 156
 
... ...
@@ -1,19 +1,35 @@
1
+/* Copyright (C) CJ Affiliate
2
+ *
3
+ * You may use, distribute and modify this code under  the
4
+ * terms of the  GNU General Public License  version 2  or
5
+ * later.
6
+ *
7
+ * You should have received a copy of the license with this
8
+ * file. If not, you will find a copy in the "LICENSE" file
9
+ * at https://github.com/cjdev/dual-control.
10
+ */
11
+
1 12
 #include <cstdlib>
2 13
 #include <memory>
3 14
 
4 15
 #include "sys_stdlib.h"
5 16
 
6
-namespace {
7
-    class impl : public stdlib_ifc {
8
-        public:
9
-            int rand() const override {
10
-                return ::rand();
11
-            }
17
+namespace
18
+{
19
+class impl : public stdlib_ifc
20
+{
21
+public:
22
+    int rand() const override
23
+    {
24
+        return ::rand();
25
+    }
12 26
 
13
-    };
27
+};
14 28
 }
15 29
 
16
-stdlib const &stdlib::get() {
30
+stdlib const &stdlib::get()
31
+{
17 32
     static stdlib singleton {std::make_shared<impl>()};
18 33
     return singleton;
19 34
 }
35
+
... ...
@@ -1,23 +1,43 @@
1
+/* Copyright (C) CJ Affiliate
2
+ *
3
+ * You may use, distribute and modify this code under  the
4
+ * terms of the  GNU General Public License  version 2  or
5
+ * later.
6
+ *
7
+ * You should have received a copy of the license with this
8
+ * file. If not, you will find a copy in the "LICENSE" file
9
+ * at https://github.com/cjdev/dual-control.
10
+ */
11
+
1 12
 #ifndef SYS_CSTDLIB_H_
2 13
 #define SYS_CSTDLIB_H_
3 14
 
4 15
 #include <memory>
5 16
 
6
-class stdlib_ifc {
7
-    public:
8
-        virtual int rand() const {return 0;}
17
+class stdlib_ifc
18
+{
19
+public:
20
+    virtual int rand() const
21
+    {
22
+        return 0;
23
+    }
9 24
 };
10 25
 
11
-class stdlib {
12
-    public:
13
-        using delegate = std::shared_ptr<stdlib_ifc>;
14
-    private:
15
-       delegate delegate_;
16
-    public:
17
-       stdlib(delegate delegate = std::make_shared<stdlib_ifc>()) : delegate_(delegate) {}
18
-      int rand() const { return delegate_->rand(); }
19
-      static const stdlib& get();
26
+class stdlib
27
+{
28
+public:
29
+    using delegate = std::shared_ptr<stdlib_ifc>;
30
+private:
31
+    delegate delegate_;
32
+public:
33
+    stdlib (delegate delegate = std::make_shared<stdlib_ifc>()) : delegate_
34
+        (delegate) {}
35
+    int rand() const
36
+    {
37
+        return delegate_->rand();
38
+    }
39
+    static const stdlib &get();
20 40
 };
21 41
 
22
-
23 42
 #endif
43
+
... ...
@@ -24,7 +24,8 @@ public:
24 24
     {
25 25
         return -1;
26 26
     }
27
-    virtual const char *getlogin() const {
27
+    virtual const char *getlogin() const
28
+    {
28 29
         return "";
29 30
     }
30 31
 };
... ...
@@ -44,7 +45,8 @@ public:
44 45
     {
45 46
         return delegate_->sysconf (name);
46 47
     }
47
-    const char *getlogin() const {
48
+    const char *getlogin() const
49
+    {
48 50
         return delegate_->getlogin();
49 51
     }
50 52
     static unistd create();