svn commit: r319844 - head/lib/libcam/tests
Ngie Cooper
ngie at FreeBSD.org
Mon Jun 12 02:12:24 UTC 2017
Author: ngie
Date: Mon Jun 12 02:12:22 2017
New Revision: 319844
URL: https://svnweb.freebsd.org/changeset/base/319844
Log:
Add positive and negative testcases for cam_get_device(3)
MFC after: 1 month
Submitted by: Evan Cramer <evan.cramer at isilon.com>
Modified:
head/lib/libcam/tests/libcam_test.c
Modified: head/lib/libcam/tests/libcam_test.c
==============================================================================
--- head/lib/libcam/tests/libcam_test.c Mon Jun 12 01:26:36 2017 (r319843)
+++ head/lib/libcam/tests/libcam_test.c Mon Jun 12 02:12:22 2017 (r319844)
@@ -30,6 +30,7 @@ __FBSDID("$FreeBSD$");
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
+#include <stdlib.h>
#include <camlib.h>
#include <atf-c.h>
@@ -58,6 +59,75 @@ cam_has_error(void)
return (strlen(cam_errbuf) != 0);
}
+ATF_TC_WITHOUT_HEAD(cam_get_device_negative_test_NULL_path);
+ATF_TC_BODY(cam_get_device_negative_test_NULL_path, tc)
+{
+ char parsed_dev_name[DEV_IDLEN + 1];
+ int parsed_unit;
+
+ ATF_REQUIRE_MSG(cam_get_device(NULL, parsed_dev_name,
+ nitems(parsed_dev_name), &parsed_unit) == -1,
+ "cam_get_device succeeded unexpectedly");
+}
+
+ATF_TC_WITHOUT_HEAD(cam_get_device_negative_test_bad_path);
+ATF_TC_BODY(cam_get_device_negative_test_bad_path, tc)
+{
+ char parsed_dev_name[DEV_IDLEN + 1];
+ int parsed_unit;
+
+ ATF_REQUIRE_MSG(cam_get_device("1ada", parsed_dev_name,
+ nitems(parsed_dev_name), &parsed_unit) == -1,
+ "cam_get_device succeeded unexpectedly");
+}
+
+ATF_TC_WITHOUT_HEAD(cam_get_device_negative_test_nul_path);
+ATF_TC_BODY(cam_get_device_negative_test_nul_path, tc)
+{
+ char parsed_dev_name[DEV_IDLEN + 1];
+ int parsed_unit;
+
+ ATF_REQUIRE_MSG(cam_get_device("", parsed_dev_name,
+ nitems(parsed_dev_name), &parsed_unit) == -1,
+ "cam_get_device succeeded unexpectedly");
+}
+
+ATF_TC_WITHOUT_HEAD(cam_get_device_negative_test_root);
+ATF_TC_BODY(cam_get_device_negative_test_root, tc)
+{
+ char parsed_dev_name[DEV_IDLEN + 1];
+ int parsed_unit;
+
+ ATF_REQUIRE_MSG(cam_get_device("/", parsed_dev_name,
+ nitems(parsed_dev_name), &parsed_unit) == -1,
+ "cam_get_device succeeded unexpectedly");
+}
+
+ATF_TC_WITHOUT_HEAD(cam_get_device_positive_test);
+ATF_TC_BODY(cam_get_device_positive_test, tc)
+{
+ char expected_dev_name[] = "foo";
+ char parsed_dev_name[DEV_IDLEN + 1];
+ int expected_unit, parsed_unit;
+
+ expected_unit = 1;
+
+ ATF_REQUIRE_MSG(cam_get_device("/dev/foo1", parsed_dev_name,
+ nitems(parsed_dev_name), &parsed_unit) == 0,
+ "cam_get_device failed");
+ ATF_REQUIRE_STREQ(parsed_dev_name, expected_dev_name);
+ ATF_REQUIRE(parsed_unit == expected_unit);
+
+ strcpy(parsed_dev_name, "");
+ parsed_unit = -1;
+
+ ATF_REQUIRE_MSG(cam_get_device("foo1", parsed_dev_name,
+ nitems(parsed_dev_name), &parsed_unit) == 0,
+ "cam_get_device failed");
+ ATF_REQUIRE_STREQ(parsed_dev_name, expected_dev_name);
+ ATF_REQUIRE(parsed_unit == expected_unit);
+}
+
ATF_TC(cam_open_device_negative_test_O_RDONLY);
ATF_TC_HEAD(cam_open_device_negative_test_O_RDONLY, tc)
{
@@ -206,6 +276,11 @@ ATF_TC_BODY(cam_freeccb_negative_test_NULL, tc)
ATF_TP_ADD_TCS(tp)
{
+ ATF_TP_ADD_TC(tp, cam_get_device_negative_test_NULL_path);
+ ATF_TP_ADD_TC(tp, cam_get_device_negative_test_bad_path);
+ ATF_TP_ADD_TC(tp, cam_get_device_negative_test_nul_path);
+ ATF_TP_ADD_TC(tp, cam_get_device_negative_test_root);
+ ATF_TP_ADD_TC(tp, cam_get_device_positive_test);
ATF_TP_ADD_TC(tp, cam_open_device_negative_test_O_RDONLY);
ATF_TP_ADD_TC(tp, cam_open_device_negative_test_nonexistent);
ATF_TP_ADD_TC(tp, cam_open_device_negative_test_unprivileged);
More information about the svn-src-head
mailing list