Browse code
removes erroneously created file
Showing 1 changed files
1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,106 +0,0 @@ |
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 |
- |
|
12 |
-#include <memory> |
|
13 |
-#include <cstring> |
|
14 |
-#include <pwd.h> |
|
15 |
-#include <cstdio> |
|
16 |
-#include <sys/stat.h> |
|
17 |
-#include <fstream> |
|
18 |
-#include <istream> |
|
19 |
- |
|
20 |
-#include "token.h" |
|
21 |
-#include "test_util.h" |
|
22 |
-#include "user.h" |
|
23 |
- |
|
24 |
-class fake_file_reader : public file_reader_ifc |
|
25 |
-{ |
|
26 |
-private: |
|
27 |
- std::string file_path_; |
|
28 |
-public: |
|
29 |
- bool open (std::ifstream &token_file, const std::string &file_path) |
|
30 |
- { |
|
31 |
- file_path_ = file_path; |
|
32 |
- return true; |
|
33 |
- } |
|
34 |
- std::string getline (std::ifstream &token_file, std::string &fetched_token) |
|
35 |
- { |
|
36 |
- return file_path_; |
|
37 |
- } |
|
38 |
-}; |
|
39 |
- |
|
40 |
-class file_reader_with_open_err : public file_reader_ifc { |
|
41 |
- public: |
|
42 |
- bool open (std::ifstream &token_file, std::string &fetched_token) { |
|
43 |
- return false; |
|
44 |
- } |
|
45 |
-}; |
|
46 |
- |
|
47 |
-class fake_user : public user_ifc |
|
48 |
-{ |
|
49 |
-private: |
|
50 |
- std::string home_directory_; |
|
51 |
-public: |
|
52 |
- fake_user (std::string &user_name) : |
|
53 |
- home_directory_ ("home/" + user_name) |
|
54 |
- { |
|
55 |
- } |
|
56 |
- std::string home_directory() |
|
57 |
- { |
|
58 |
- return home_directory_; |
|
59 |
- } |
|
60 |
-}; |
|
61 |
- |
|
62 |
-int reads_from_the_right_file () |
|
63 |
-{ |
|
64 |
- //given |
|
65 |
- file_reader test_file_reader (file_reader::delegate (new fake_file_reader)); |
|
66 |
- std::string user_name = "user"; |
|
67 |
- std::string expected = "home/" + user_name + "/.dual_control"; |
|
68 |
- user test_user (user::delegate (new fake_user (user_name))); |
|
69 |
- user_token_supplier supplier (user_token_supplier::create ( |
|
70 |
- test_file_reader)); |
|
71 |
- |
|
72 |
- //when |
|
73 |
- std::string actual = supplier.token (test_user); |
|
74 |
- |
|
75 |
- //then |
|
76 |
- check (actual == expected, "read wrong file"); |
|
77 |
- succeed(); |
|
78 |
-} |
|
79 |
- |
|
80 |
-int returns_empty_string_if_file_open_error() { |
|
81 |
- //given |
|
82 |
- file_reader test_file_reader (file_reader::delegate (new file_reader_with_open_err)); |
|
83 |
- user_token_supplier supplier (user_token_supplier::create ( |
|
84 |
- test_file_reader)); |
|
85 |
- |
|
86 |
- |
|
87 |
- //when |
|
88 |
- |
|
89 |
- //then |
|
90 |
-} |
|
91 |
- |
|
92 |
-RESET_VARS_START |
|
93 |
-RESET_VARS_END |
|
94 |
- |
|
95 |
-int run_tests() |
|
96 |
-{ |
|
97 |
- test (reads_from_the_right_file); |
|
98 |
- test (returns_empty_string_if_file_open_error); |
|
99 |
- succeed(); |
|
100 |
-} |
|
101 |
- |
|
102 |
-int main (int argc, char *argv[]) |
|
103 |
-{ |
|
104 |
- return !run_tests(); |
|
105 |
-} |
|
106 |
- |