git.fiddlerwoaroof.com
Browse code

formatting; user.cc uses user::delegate

jbalcita authored on 24/04/2017 21:25:23
Showing 2 changed files
... ...
@@ -37,11 +37,13 @@ public:
37 37
     }
38 38
 };
39 39
 
40
-class file_reader_with_open_fail : public file_reader_ifc {
41
-    public:
42
-        bool open (std::ifstream &token_file, std::string &fetched_token) {
43
-            return false;
44
-        }
40
+class file_reader_with_open_fail : public file_reader_ifc
41
+{
42
+public:
43
+    bool open (std::ifstream &token_file, std::string &fetched_token)
44
+    {
45
+        return false;
46
+    }
45 47
 };
46 48
 
47 49
 class fake_user : public user_ifc
... ...
@@ -78,9 +80,11 @@ int reads_from_the_right_file ()
78 80
     succeed();
79 81
 }
80 82
 
81
-int returns_empty_string_if_file_open_fail() {
83
+int returns_empty_string_if_file_open_fail()
84
+{
82 85
     //given
83
-    file_reader test_file_reader (file_reader::delegate (new file_reader_with_open_fail));
86
+    file_reader test_file_reader (file_reader::delegate (new
87
+                                  file_reader_with_open_fail));
84 88
     user test_user (user::delegate (new fake_user));
85 89
     user_token_supplier supplier (user_token_supplier::create (
86 90
                                       test_file_reader));
... ...
@@ -89,7 +93,7 @@ int returns_empty_string_if_file_open_fail() {
89 93
     std::string actual = supplier.token (test_user);
90 94
 
91 95
     //then
92
-    check(actual == "", "should have returned empty string");
96
+    check (actual == "", "should have returned empty string");
93 97
     succeed();
94 98
 }
95 99
 
... ...
@@ -51,8 +51,7 @@ public:
51 51
         std::vector<user> return_value;
52 52
 
53 53
         if (!result && found_passwd) {
54
-            return_value.push_back (std::shared_ptr<user_ifc> (new user_impl (
55
-                                        sys_passwd)));
54
+            return_value.push_back (user::delegate (new user_impl (sys_passwd)));
56 55
         }
57 56
 
58 57
         return return_value;
... ...
@@ -65,41 +64,3 @@ directory directory::create (unistd &unistd, pwd &pwd)
65 64
     return directory (delegate (new directory_impl (unistd, pwd)));
66 65
 }
67 66
 
68
-/*
69
-class concrete_user : public user
70
-{
71
-private:
72
-    std::vector<char> buffer_;
73
-    std::shared_ptr<struct passwd> store_;
74
-public:
75
-    concrete_user (const std::vector<char> &buffer,
76
-                   const std::shared_ptr<struct passwd> &store);
77
-};
78
-
79
-concrete_user::concrete_user (const std::vector<char> &buffer,
80
-                              const std::shared_ptr<struct passwd> &store) :
81
-    buffer_ (buffer),
82
-    store_ (store),
83
-    user (store.get())
84
-{
85
-}
86
-
87
-const std::shared_ptr<user> create_user (const std::string &user_name)
88
-{
89
-    std::vector<char> buffer (sysconf (_SC_GETPW_R_SIZE_MAX));
90
-    std::shared_ptr<struct passwd> sys_passwd (new struct passwd);
91
-    struct passwd *found_passwd (0);
92
-
93
-    getpwnam_r (user_name.c_str(), sys_passwd.get(), buffer.data(),
94
-                buffer.size(), &found_passwd);
95
-
96
-    std::shared_ptr<user> rval;
97
-
98
-    if (found_passwd) {
99
-        rval.reset (new concrete_user (buffer, sys_passwd));
100
-    }
101
-
102
-    return rval;
103
-}
104
-*/
105
-