Browse code
compiles but doesn't test
Greg Wiley authored on 21/04/2017 22:45:01
Showing 7 changed files
Showing 7 changed files
... | ... |
@@ -1,8 +1,9 @@ |
1 | 1 |
CXXFLAGS += -fPIC -fno-stack-protector -std=c++14 |
2 | 2 |
CFLAGS += -fPIC -fno-stack-protector |
3 | 3 |
|
4 |
-OBJS = dual_control.o request.o dual_control_integrate.o validator.o conversation.o |
|
5 |
-TESTS = dual_control_test validator_test conversation_test request_test |
|
4 |
+OBJS = dual_control.o request.o dual_control_integrate.o validator.o conversation.o user.o \ |
|
5 |
+ sys_unistd.o sys_pwd.o |
|
6 |
+TESTS = dual_control_test validator_test conversation_test request_test user_test |
|
6 | 7 |
TESTOBJS = $(patsubst %,%.o,$(TESTS)) |
7 | 8 |
SRCS := $(OBJS:.o=.cc) $(TESTOBJS:.o=.cc) |
8 | 9 |
|
9 | 10 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,20 @@ |
1 |
+#include "sys_pwd.h" |
|
2 |
+ |
|
3 |
+#include <pwd.h> |
|
4 |
+ |
|
5 |
+namespace { |
|
6 |
+ class impl : public pwd_ifc { |
|
7 |
+ public: |
|
8 |
+ int getpwnam_r(const char *user_name, passwd *out, char *buffer, |
|
9 |
+ size_t buffer_sz, passwd **result) { |
|
10 |
+ return ::getpwnam_r(user_name, out, buffer, buffer_sz, result); |
|
11 |
+ } |
|
12 |
+ |
|
13 |
+ }; |
|
14 |
+ static pwd system_pwd(pwd::delegate(new impl)); |
|
15 |
+} |
|
16 |
+ |
|
17 |
+pwd pwd::system() { |
|
18 |
+ return system_pwd; |
|
19 |
+} |
|
20 |
+ |
0 | 21 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,33 @@ |
1 |
+#ifndef _SYS_PWD_H |
|
2 |
+#define _SYS_PWD_H |
|
3 |
+ |
|
4 |
+#include <memory> |
|
5 |
+#include <pwd.h> |
|
6 |
+ |
|
7 |
+class pwd_ifc { |
|
8 |
+ public: |
|
9 |
+ virtual int getpwnam_r(const char *user_name, passwd *out, char *buffer, |
|
10 |
+ size_t buffer_sz, passwd **result) { |
|
11 |
+ *result = 0; |
|
12 |
+ return 0; |
|
13 |
+ }; |
|
14 |
+}; |
|
15 |
+ |
|
16 |
+class pwd : public pwd_ifc { |
|
17 |
+ public: |
|
18 |
+ typedef std::shared_ptr<pwd_ifc> delegate; |
|
19 |
+ |
|
20 |
+ private: |
|
21 |
+ delegate delegate_; |
|
22 |
+ |
|
23 |
+ public: |
|
24 |
+ pwd(const delegate delegate) : delegate_(delegate) {} |
|
25 |
+ pwd() : delegate_(delegate(new pwd_ifc)) {} |
|
26 |
+ int getpwnam_r(const char *user_name, passwd *out, char *buffer, |
|
27 |
+ size_t buffer_sz, passwd **result) { |
|
28 |
+ return delegate_-> getpwnam_r(user_name, out, buffer, buffer_sz, result); |
|
29 |
+ } |
|
30 |
+ static pwd system(); |
|
31 |
+}; |
|
32 |
+ |
|
33 |
+#endif |
0 | 34 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,16 @@ |
1 |
+#include "sys_unistd.h" |
|
2 |
+#include <unistd.h> |
|
3 |
+ |
|
4 |
+namespace { |
|
5 |
+ class impl : public unistd_ifc { |
|
6 |
+ public: |
|
7 |
+ long int sysconf(int name) { |
|
8 |
+ return ::sysconf(name); |
|
9 |
+ } |
|
10 |
+ }; |
|
11 |
+ static unistd sys_unistd(unistd::delegate(new impl)); |
|
12 |
+} |
|
13 |
+ |
|
14 |
+unistd unistd::system() { |
|
15 |
+ return sys_unistd; |
|
16 |
+} |
0 | 17 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,29 @@ |
1 |
+#ifndef _SYS_UNISTD_H_ |
|
2 |
+#define _SYS_UNISTD_H_ |
|
3 |
+ |
|
4 |
+#include <memory> |
|
5 |
+ |
|
6 |
+class unistd_ifc { |
|
7 |
+ public: |
|
8 |
+ virtual long int sysconf(int name) { return -1; } |
|
9 |
+}; |
|
10 |
+ |
|
11 |
+class unistd : public unistd_ifc { |
|
12 |
+ public: |
|
13 |
+ typedef std::shared_ptr<unistd_ifc> delegate; |
|
14 |
+ |
|
15 |
+ private: |
|
16 |
+ delegate delegate_; |
|
17 |
+ |
|
18 |
+ public: |
|
19 |
+ unistd(delegate delegate): delegate_(delegate) {} |
|
20 |
+ unistd() : delegate_(delegate(new unistd_ifc)) {} |
|
21 |
+ long int sysconf(int name) { |
|
22 |
+ return delegate_->sysconf(name); |
|
23 |
+ } |
|
24 |
+ static unistd system(); |
|
25 |
+}; |
|
26 |
+ |
|
27 |
+ |
|
28 |
+ |
|
29 |
+#endif |
... | ... |
@@ -10,26 +10,18 @@ |
10 | 10 |
*/ |
11 | 11 |
|
12 | 12 |
#include <memory> |
13 |
-#include <vector> |
|
14 |
-#include <string> |
|
15 |
-#include <pwd.h> |
|
16 |
-#include <unistd.h> |
|
17 |
-#include <iostream> |
|
18 | 13 |
|
19 | 14 |
#include "user.h" |
20 |
-#include "test_support.h" |
|
21 | 15 |
|
22 |
-user::user (struct passwd *sys_info) : info (sys_info) |
|
23 |
-{ |
|
24 |
-} |
|
25 |
- |
|
26 |
-std::string user::home_directory() |
|
27 |
-{ |
|
28 |
- return info->pw_dir; |
|
16 |
+namespace { |
|
17 |
+ class directory_impl : public directory_ifc { |
|
18 |
+ public: |
|
19 |
+ std::vector<user> find_user (const std::string &user_name); |
|
20 |
+ }; |
|
29 | 21 |
} |
30 | 22 |
|
31 |
-// concrete user implementation |
|
32 | 23 |
|
24 |
+/* |
|
33 | 25 |
class concrete_user : public user |
34 | 26 |
{ |
35 | 27 |
private: |
... | ... |
@@ -65,4 +57,5 @@ const std::shared_ptr<user> create_user (const std::string &user_name) |
65 | 57 |
|
66 | 58 |
return rval; |
67 | 59 |
} |
60 |
+*/ |
|
68 | 61 |
|
... | ... |
@@ -9,28 +9,26 @@ |
9 | 9 |
* at https://github.com/cjdev/dual-control. |
10 | 10 |
*/ |
11 | 11 |
|
12 |
-#include <memory> |
|
13 |
-#include <iostream> |
|
14 | 12 |
#include "user.h" |
15 | 13 |
#include "test_util.h" |
16 | 14 |
|
17 |
-bool gets_home_directory() |
|
18 |
-{ |
|
19 |
- //given |
|
20 |
- const char *expected_home_directory = "home/msmith"; |
|
21 |
- struct passwd test_passwd; |
|
22 |
- test_passwd.pw_dir = const_cast<char *> (expected_home_directory); |
|
23 |
- user test_user (&test_passwd); |
|
24 |
- |
|
25 |
- //when |
|
26 |
- std::string actual_home_directory = test_user.home_directory(); |
|
27 |
- |
|
28 |
- //then |
|
29 |
- check (expected_home_directory == actual_home_directory, |
|
30 |
- "directories do not match"); |
|
31 |
- return expected_home_directory == actual_home_directory; |
|
15 |
+int find_user_happy() { |
|
16 |
+ fail(); |
|
17 |
+} |
|
18 |
+ |
|
19 |
+RESET_VARS_START |
|
20 |
+RESET_VARS_END |
|
21 |
+ |
|
22 |
+int run_tests() { |
|
23 |
+ test(find_user_happy); |
|
24 |
+ succeed(); |
|
25 |
+} |
|
26 |
+ |
|
27 |
+int main(int argc, char **argv) { |
|
28 |
+ return !run_tests(); |
|
32 | 29 |
} |
33 | 30 |
|
31 |
+/* |
|
34 | 32 |
std::shared_ptr<struct passwd> fake_passwd; |
35 | 33 |
int fake_getpwnam_r (const char *nam, struct passwd *pwd, char *buffer, |
36 | 34 |
size_t bufsize, struct passwd **result) |
... | ... |
@@ -93,4 +91,5 @@ int main (int argc, char *argv[]) |
93 | 91 |
{ |
94 | 92 |
return !run_tests(); |
95 | 93 |
} |
94 |
+*/ |
|
96 | 95 |
|