Wednesday, January 27 in Class Individual
Wednesday, January 27 in Class Individual
Report 1 Specification
Due: Wednesday, January 27
Where: In class
Format: Individual
If the class has begun your report is late
1 Main Points
Be sure to read and follow all the guidelines from the links on reports and academic honesty from the
WWW home page for the course. The specification is the union of this document plus the program text
you are given.
Package 2
• Cover page (Standard version) – attached to announcement. Fill in your name and Prism username
• Your functional testing report.
Package 3
Submit electronically before the deadline your Sreadhex project, where Sreadhex is the directory
containing the project.
submit 4313 r1 Sreadhex
2 To get started
Section 2.1 describes how to get started with the open office bug reports. Section 2.2 describes how to get
started with the functional testing system.
2.1 Run Open Office
Run Open Office by typing ooffice on Prism to get familiar with it. You can also install Open Office on
your computer by downloading it from http://www.openoffice.org.
There are three different versions of Open Office available on Prism. You can run each one with the
following commands. For this report you are to use version 3.3.1, which is the default download for both
Mac OS and Windows.
• ooffice.2.4.1
• ooffice.3.1.1
• ooffice – also ooffice.3.1.0
Sreadhex should be compiled and executable. Select the project in the package tab, select Run –> Run
as –> Junit Test. You can also be in a listing of one of the test files, when you select Run –> Run as –>
Junit Test, then only that test file will be run.
4.1 Motivation
sreadhex is a function that takes a string of ASCII characters where each character represents a
hexadecimal digit. For example, the string “A49F” represents the hexadecimal digits 10, 4, 9, and 15.
Each digit can be represented in four bits, thus the string corresponds to the bit sequences, 1010, 0100,
1001 and 1111. As a consequence, a pair of digits can be packed into a byte, while a string of digits can be
packed into a byte-array of half the length of the string.
A49F byte 1: 10100100 and byte2: 10011111
Question: What should be done if there are an odd number of characters? Since two digits fit per byte,
what would be done with the unused half of the last byte in the result string? Given, “34ABF”, what value
should the ???? below have?
Byte 1: 00110100
Byte 2: 10101011
Byte 3: 1111????
Answer: The solution is not to put the last digit in the result array, but to return it as a separate return
value. Thus the result string always has an even number of digits. In the above case, the result string
would be the first two bytes and the integer 15. The “extra” return value is typically used in the next call to
sreadhex. That is, if 15 is returned by one call, then the next call has 15 as input, where it is used as the
first 4 bits of the next result byte-array.
Question: What should be done if there are characters in the source string that do not represent
hexadecimal digits?
Answer: sreadhex completely ignores them. Thus, all of the following strings will yield the same
result.
“34AB”
“3 4 A B”
“3G4GAMB-“
4.3 Specification
Here is the specification for sreadhex. It is complex. Other styles of specification read more naturally but
are harder to use for devising test cases. To make the specification easier to read, names of variables and
definitions are in bold.
sreadhex(str, rlen, nread, odd_digit, s)
• str is a byte array to fill. It’s the destination.
• rlen is the maximum number of bytes to be filled in str.
• nread is a pointer to an integer. When the routine finishes, it leaves the number of bytes it used in
that integer.
• odd_digit is a pointer to an integer. The caller uses it to pass in the first digit (if the last call used
an odd number of digits); the routine leaves either –1 or the extra digit in it after return. (The
“odd” in odd_digit refers to its being set when there are an odd number of hexadecimal characters
to be placed in str.
• s is a null-terminated string. It is the source of hexadecimal characters.
• sreadhex returns 0 or 1. 1 means sreadhex ran out of characters before filling str.
Definitions
There are 22 hexadecimal characters. They are listed here, along with their corresponding integer
values. Notice that both uppercase and lowercase characters are used.
0 1 2 3 4 5 6 7 8 9 A B C D E F a b c d e f
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 10 11 12 13 14 15
hex_char[index] – This is the indexth hexadecimal character in s. For example, if s is “Aa-0”, then
hex_char[0] is ‘A’
hex_char[1] is ‘a’
hex_char[2] is ‘0’
Notice that the dash is not counted. Numbering begins with 0.
num_hex_chars is the number of hexadecimal characters in s. If s is “Aa-0”, then
num_hex_chars is 3.
start – This is the location where the value of the first hexadecimal character in s is to be placed in str.
if (*odd_digit == -1) then start is 0
else start is 1
digit[index] – This is the indexth digit (4-bit chunk) of str. Digits 0 and 1 are in byte 0 of str, digits 2
and 3 are in byte 1, and so on. Remember that *odd_digit, if not –1, is placed in digit 0.
Preconditions
1. Assumed: str is a non-null pointer to an array that can hold rlen bytes (hence 2*rlen
digits).
2. Assumed: rlen ≥ 0.
3. Assumed: nread is a non-null pointer to an integer.
4. Assumed: odd_digit is a non-null pointer to an integer.
5. Assumed: *odd_digit is in the range [–1, 15].
6. Assumed: s is a non—null pointer to a null-terminated string.
7. Validated: rlen is not 0. On failure: *nread is 0. The return value is 0.
Postconditions
1. (An even number of digits that don’t fill str: use them all)
if start + num_hex_chars < rlen*2
and start + num_hex_chars is even
then A. the return value is 1.
B. *nread is (start + num_hex_chars)/2.
C. For any hexadecimal character in s at index index,
digit[start + index] = hex_char[index] (For example, if character 0 is ‘9’ and start
th
is 0, 9 is placed as the 0 digit of str.
D. *odd_digit is –1.
2. (An odd number of digits that don’t fill str; use them all)
if start + num_hex_chars < rlen*2
and start + num_hex_chars is odd
then A. the return value is 1.
B. *nread is (start + num_hex_chars – 1)/2.
C. For any hexadecimal character in s at index index except the final hexadecimal
character, digit[start + index] = hex_char[index].
D. *odd_digit is set to the value of the last hexadecimal character in s.
3. (Enough digits to fill str; ignore any excess)
if start + num_hex_chars ≥ rlen*2
and start + num_hex_chars is odd
then A. the return value is 0.
B. *nread is rlen.
C. For any hexadecimal character in s at index index such that start + index < rlen*2
digit[start + index] = hex_char[index]
D. *odd_digit is unchanged.
4. if *odd_digit is initially ≥ 0
then digit[0] = the initial value of *odd_digit.
The following is the program in C. This version contains a fault that has long since been fixed in later
versions. This version, its name is v1 (see BoundaryTest.java) has been translated into Java (I hope
correctly, thereby containing that bug and no other). v2 contains one seeded bug. v3 contains a different
seeded bug. v4 contains both bugs in v2 and v3.
Line 13 – The program gets characters via sgetc. In the original program, sgetc got characters from a
stream datatype; in this simpler version it picks characters from a string.
Lines 10, 26 – The program uses a lookup table, decoder, to convert characters into values. The character
is used as an index in the table. decoder[character] is the corresponding value. The table is initialized the
first time sreadhex is called. In line 26 decoder is set to point to the last 256 characters of the decode_hex
array. The first character (decoder_hex[0] or decoder[-1] indicates whether the table has already been
initialized.
Lines 28-35 – decoder is initialized with memset, which sets every entry to hex_none indicating that the
corresponding character is not hexadecimal. Then the entries for hexadecimal characters are set by
iterating through a string of all such characters, calculating the value, and placing that in decoder. Note
that the characters “abcdef” are given the same values as “ABCDEF”. Character ‘\0’ (which is found at the
end of a C string) has value hex_eofc (value 0x20), which causes sreadhex to return.
Lines 36-42 – The first while loop finds the first digit in a byte; the second one finds the second. The loops
skip non-hexadecimal characters. If the first digit is passed in, it should be in the range [0 .. 15]. –1 means
no digit was passed in. The case on line 24 converts the –1 to a large positive number, so that val1 ≤ 0xf
evaluates to false.
5 Grading scheme
The grade for the report is partitioned into the following parts.
• Part 1: Overall presentation – 10%
• Part 2: Bug reports – 36% – 18% each
• Part 3: Boundary value testing – 18% – half for the test cases and half for the report
• Part 4: Equivalence class testing – 18% – half for the test cases and half for the report
• Part 5: Decision table testing – 18% – half for the test cases and half for the report