From owner-svn-src-all@FreeBSD.ORG Wed Nov 7 22:03:59 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id BD3E399C; Wed, 7 Nov 2012 22:03:59 +0000 (UTC) (envelope-from sjg@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 888AA8FC08; Wed, 7 Nov 2012 22:03:59 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.5/8.14.5) with ESMTP id qA7M3xh0014447; Wed, 7 Nov 2012 22:03:59 GMT (envelope-from sjg@svn.freebsd.org) Received: (from sjg@localhost) by svn.freebsd.org (8.14.5/8.14.5/Submit) id qA7M3xCc014445; Wed, 7 Nov 2012 22:03:59 GMT (envelope-from sjg@svn.freebsd.org) Message-Id: <201211072203.qA7M3xCc014445@svn.freebsd.org> From: "Simon J. Gerraty" Date: Wed, 7 Nov 2012 22:03:59 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r242713 - head/lib/libcrypt/tests X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 07 Nov 2012 22:03:59 -0000 Author: sjg Date: Wed Nov 7 22:03:59 2012 New Revision: 242713 URL: http://svnweb.freebsd.org/changeset/base/242713 Log: Simple unit-tests for libcrypt, to show how easy it is. Approved by: marcel (mentor) Added: head/lib/libcrypt/tests/ head/lib/libcrypt/tests/Makefile (contents, props changed) head/lib/libcrypt/tests/crypt_tests.c (contents, props changed) Added: head/lib/libcrypt/tests/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/lib/libcrypt/tests/Makefile Wed Nov 7 22:03:59 2012 (r242713) @@ -0,0 +1,10 @@ +# $FreeBSD$ + +# exercise libcrypt + +TESTS_C= crypt_tests + +CFLAGS+= -I${.CURDIR:H} +LDADD+= -L${.OBJDIR:H} -lcrypt + +.include Added: head/lib/libcrypt/tests/crypt_tests.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/lib/libcrypt/tests/crypt_tests.c Wed Nov 7 22:03:59 2012 (r242713) @@ -0,0 +1,54 @@ +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include + +#include + +#define LEET "0.s0.l33t" + +ATF_TC(md5); +ATF_TC_HEAD(md5, tc) +{ + + atf_tc_set_md_var(tc, "descr", "Tests the MD5 based password hash"); +} + +ATF_TC_BODY(md5, tc) +{ + const char want[] = "$1$deadbeef$0Huu6KHrKLVWfqa4WljDE0"; + char *pw; + + pw = crypt(LEET, want); + ATF_CHECK_STREQ(pw, want); +} + +ATF_TC(invalid); +ATF_TC_HEAD(invalid, tc) +{ + + atf_tc_set_md_var(tc, "descr", "Tests that invalid password fails"); +} + +ATF_TC_BODY(invalid, tc) +{ + const char want[] = "$1$cafebabe$0Huu6KHrKLVWfqa4WljDE0"; + char *pw; + + pw = crypt(LEET, want); + ATF_CHECK(strcmp(pw, want) != 0); +} + +/* + * This function must not do anything except enumerate + * the test cases, else atf-run is likely to be upset. + */ +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, md5); + ATF_TP_ADD_TC(tp, invalid); + return atf_no_error(); +}