diff options
author | Bartosz Golaszewski <bartekgola@gmail.com> | 2014-06-22 16:30:41 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2014-06-22 16:30:41 +0200 |
commit | 3ed81cf0529145d04299c4cd48b1aaab2fe36193 (patch) | |
tree | f8d40bf4c55c9dadba0773543048a5d69b695002 /libbb/obscure.c | |
parent | 5d2e409ef8224dc32fde59702e8ec90b231441ed (diff) | |
download | busybox-w32-3ed81cf0529145d04299c4cd48b1aaab2fe36193.tar.gz busybox-w32-3ed81cf0529145d04299c4cd48b1aaab2fe36193.tar.bz2 busybox-w32-3ed81cf0529145d04299c4cd48b1aaab2fe36193.zip |
unit-tests: implement the unit-testing framework
This set of patches adds a simple unit-testing framework to Busybox
unit-tests: add some helper macros for unit-test framework implementation
unit-tests: implement the unit-testing framework
unit-tests: add basic documentation on writing the unit test cases
unit-tests: modify the Makefile 'test' target to run unit-tests too
unit-tests: add two example test cases
unit-tests: modify the existing strrstr test code to use the unit-test framework
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb/obscure.c')
-rw-r--r-- | libbb/obscure.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/libbb/obscure.c b/libbb/obscure.c index 24c4ac917..ad17d1ff1 100644 --- a/libbb/obscure.c +++ b/libbb/obscure.c | |||
@@ -182,3 +182,41 @@ int FAST_FUNC obscure(const char *old, const char *newval, const struct passwd * | |||
182 | } | 182 | } |
183 | return 0; | 183 | return 0; |
184 | } | 184 | } |
185 | |||
186 | #if ENABLE_UNIT_TEST | ||
187 | |||
188 | /* Test obscure_msg() instead of obscure() in order not to print anything. */ | ||
189 | |||
190 | static const struct passwd pw = { | ||
191 | .pw_name = (char *)"johndoe", | ||
192 | .pw_gecos = (char *)"John Doe", | ||
193 | }; | ||
194 | |||
195 | BBUNIT_DEFINE_TEST(obscure_weak_pass) | ||
196 | { | ||
197 | /* Empty password */ | ||
198 | BBUNIT_ASSERT_NOTNULL(obscure_msg("Ad4#21?'S|", "", &pw)); | ||
199 | /* Pure numbers */ | ||
200 | BBUNIT_ASSERT_NOTNULL(obscure_msg("Ad4#21?'S|", "23577315", &pw)); | ||
201 | /* Similar to pw_name */ | ||
202 | BBUNIT_ASSERT_NOTNULL(obscure_msg("Ad4#21?'S|", "johndoe123%", &pw)); | ||
203 | /* Similar to pw_gecos, reversed */ | ||
204 | BBUNIT_ASSERT_NOTNULL(obscure_msg("Ad4#21?'S|", "eoD nhoJ^44@", &pw)); | ||
205 | /* Similar to the old password */ | ||
206 | BBUNIT_ASSERT_NOTNULL(obscure_msg("Ad4#21?'S|", "d4#21?'S", &pw)); | ||
207 | /* adjacent letters */ | ||
208 | BBUNIT_ASSERT_NOTNULL(obscure_msg("Ad4#21?'S|", "qwerty123", &pw)); | ||
209 | /* Many similar chars */ | ||
210 | BBUNIT_ASSERT_NOTNULL(obscure_msg("Ad4#21?'S|", "^33Daaaaaa1", &pw)); | ||
211 | |||
212 | BBUNIT_ENDTEST; | ||
213 | } | ||
214 | |||
215 | BBUNIT_DEFINE_TEST(obscure_strong_pass) | ||
216 | { | ||
217 | BBUNIT_ASSERT_NULL(obscure_msg("Rt4##2&:'|", "}(^#rrSX3S*22", &pw)); | ||
218 | |||
219 | BBUNIT_ENDTEST; | ||
220 | } | ||
221 | |||
222 | #endif /* ENABLE_UNIT_TEST */ | ||