2 * Copyright 2018, Sine Nomine Associates and others.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #include <afsconfig.h>
27 #include <afs/param.h>
29 #include <afs/afsutil.h>
30 #include <tests/tap/basic.h>
32 char *out_of_range_names[] = {
42 char *invalid_names[] = {
55 test_partition_name_to_id(void)
63 * Test conversion of XX to partition id,
64 * where XX is "a".."z", "aa"..."iu"
67 for (x = 'a'; x <= 'z'; x++, id++) {
68 sprintf(part, "%c", x);
69 is_int(id, volutil_GetPartitionID(part), "\"%s\" is %d", part, id);
71 for (x = 'a'; x <= 'i'; x++) {
72 for (y = 'a'; y <= 'z'; y++, id++) {
73 sprintf(part, "%c%c", x, y);
74 is_int(id, volutil_GetPartitionID(part), "\"%s\" is %d", part, id);
75 if (x == 'i' && y == 'u')
81 * Test conversion of /vicepXX to partition id,
82 * where XX is "a".."z", "aa"..."iu".
85 for (x = 'a'; x <= 'z'; x++, id++) {
86 sprintf(part, "/vicep%c", x);
87 is_int(id, volutil_GetPartitionID(part), "\"%s\" is %d", part, id);
89 for (x = 'a'; x <= 'i'; x++) {
90 for (y = 'a'; y <= 'z'; y++, id++) {
91 sprintf(part, "/vicep%c%c", x,y );
92 is_int(id, volutil_GetPartitionID(part), "\"%s\" is %d", part, id);
93 if (x == 'i' && y == 'u')
99 * Test conversion of vicepXX to partition id,
100 * where XX is "a".."z", "aa"..."iu".
103 for (x = 'a'; x <= 'z'; x++, id++) {
104 sprintf(part, "vicep%c", x);
105 is_int(id, volutil_GetPartitionID(part), "\"%s\" is %d", part, id);
107 for (x = 'a'; x <= 'i'; x++) {
108 for (y = 'a'; y <= 'z'; y++, id++) {
109 sprintf(part, "vicep%c%c", x,y );
110 is_int(id, volutil_GetPartitionID(part), "\"%s\" is %d", part, id);
111 if (x == 'i' && y == 'u')
117 * Test numeric names in the range "0".."254" are passed through.
119 for (id = 0; id <= 254; id++) {
120 sprintf(part, "%d", id);
121 is_int(id, volutil_GetPartitionID(part), "\"%s\" is %d", part, id);
125 * Test out of range names.
127 for (t = out_of_range_names; *t != NULL; t++) {
128 is_int(-1, volutil_GetPartitionID(*t), "\"%s\" is out of range", *t);
132 * Test invalid names.
134 for (t = invalid_names; *t != NULL; t++) {
135 is_int(-1, volutil_GetPartitionID(*t), "\"%s\" is invalid", *t);
140 test_partition_id_to_name(void)
147 * Test conversion of ids to partition names,
148 * for ids of 0 to 254.
151 for (x = 'a'; x <= 'z'; x++, id++) {
152 sprintf(part, "/vicep%c", x);
153 is_string(part, volutil_PartitionName(id), "%d is \"%s\"", id, part);
155 for (x = 'a'; x <= 'i'; x++) {
156 for (y = 'a'; y <= 'z'; y++, id++) {
157 sprintf(part, "/vicep%c%c", x,y );
158 is_string(part, volutil_PartitionName(id), "%d is \"%s\"", id, part);
159 if (x == 'i' && y == 'u')
164 /* Test out of range values. */
165 is_string("BAD VOLUME ID", volutil_PartitionName(-1), "-1 is invalid");
166 is_string("BAD VOLUME ID", volutil_PartitionName(255), "255 is invalid");
167 is_string("BAD VOLUME ID", volutil_PartitionName(256), "256 is invalid");
169 /* Test buffer too short (thread safe variant of volutil_PartitionName). */
170 is_string("SPC", volutil_PartitionName_r(0, part, 4), "buffer too short");
174 main(int argc, char **argv)
177 test_partition_name_to_id();
178 test_partition_id_to_name();