SRL Archive - Help and Support

How..what? Java Help


[XoL]

2013-04-19 14:13:50

This assignment is not about writing programs, it is about testing them. You will write test input files and run existing programs, but you will probably not write any Java code for this assignment. You need to do both parts of this assignment.
Part 1 - White Box Testing: For my Abstract Algebra class one semester, I wrote a quickie calculator using BigInteger values. The program is BigCalc.java, which you should download to your machine.

Using the source code to guide you (since this is white box testing), produce a list of input lines which use every branch in the program. That is, each line of code should be executed in at least one test case. Also, every combination of trues and falses should be tested at each if-statement. I'm not worried about whether the BigInteger package is working correctly (I'm willing to trust it), so you can write your test cases using 1 and 2 digit numbers - you don't need to use huge ones.

The calculator is intended to handle raising one number to a power, computing a number mod another, and raising one number to a power mod another (raising to the power is done first, then the mod - actually, the BigInteger code sort of does it all at once). So, expected inputs would be things like:

24 ^ 7
1010101 mod 77
30 ^ 11 mod 23
For this part of the assignment you should hand in a list of input lines indicating:

which are calculated correctly,
which produce an error message from the BigCalc program (which then resets itself and is ready for the next input), and
which produce a run-time error from Java (in other words, my program crashes).
Of course, you determine these by running the program with your test inputs.
Part 2 - Black Box Testing: While I was helping our ACM-ICPC Programming Team prepare for the programming contest, I got interested in one of the problems described here(http://www.mediafire.com/view/?i2vw81w41c12owp). I wrote a program which works most of the time, but it may go into an infinite loop occasionally (I'm not sure). An executable jar file containing my program can be found here(http://www.mediafire.com/?przbg24tyi48ocv). You should download this file to your machine.

To run this program, you need to get a command line in the directory where the jar file is stored. Then the command java -jar BoringHW.jar should run the program. It expects input from System.in and writes to System.out. So, a very simple run would look like:

C:\>java -jar BoringHW.jar
1
1 1
Case #1:
o

C:\>
For a more complicated run, you would use I/O redirection. For instance, using the input file sample-in.txt

3
3 3 1 2
6 4 5 6 1 3 2
5 3 4 5 2 1
and putting the output into sample-out.txt you would type:
java -jar BoringHW.jar <sample-in.txt >sample-out.txt
The output file would then look like this

Case #1:
+-o
|
o+
|
o
Case #2:
+--o+
| |
o-+ o+
| |
+o o
|
o
Case #3:
+o+
| |
+o o+
| |
o o
. You should make sure you can produce that output before proceeding.
Since this is black box testing, you don't have access to the source code. Your job is to produce a collection of test cases which are likely to use various parts of the program. Usually this includes variations like a trivial case (a one node tree), nodes with children only on the left, only on the right, on both sides, and combinations of these, etc.

For this part of the assignment you should hand in a list of input lines indicating:

which trees are drawn correctly,
which trees are drawn incorrectly,
which put my program into an infinite loop, and
which produce a run-time error from Java (in other words, my program crashes).
You might not be able to find test inputs for all of these four cases. Find as many as you can.
———
Bigcalc.java

import java.math.BigInteger;
import java.util.Scanner;

public class BigCalc
{
/*
* Simple calculator for RSA type demos
*
* written by mike slattery - nov 2011
*/
public static void main(String[] args)
{
Scanner kb = new Scanner(System.in);
while(true)
{
String line = kb.nextLine();
if (line.equals(""))
continue;
String[] words = line.split("\\s+");
if (!(words[1].equals("^") || words[1].equals("mod"))
|| (words.length < 3))
{
System.out.println("Unknown operation");
}
else if (words.length == 3)
{
if (words[1].equals("mod"))
{
BigInteger x = new BigInteger(words[0]);
BigInteger m = new BigInteger(words[2]);
System.out.println(x.mod(m));
}
else
{
BigInteger x = new BigInteger(words[0]);
int e = Integer.parseInt(words[2]);
System.out.println(x.pow(e));
}
}
else if (words.length != 5 || !words[3].equals("mod"))
{
System.out.println("Unknown operation");
}
else
{
BigInteger x = new BigInteger(words[0]);
BigInteger y = new BigInteger(words[2]);
BigInteger m = new BigInteger(words[4]);
System.out.println(x.modPow(y, m));
}
}

}

}

—-
So I think I understand the first one, but the second one? What is it really asking me to do, any methods to go about this?

And I do write Java code for this, even though somewhere it states I don't?

masterBB

2013-04-19 14:52:50

You don't, you may only run the .jar file with cmd.exe and you are allowed to write sample-in.txt and read sample-out.txt

Brandon

2013-04-19 17:51:26

First application has > 3 exploits to crash it..

Heap/Buffer Overflow.. Just provide an extremely long line that is roughly near 2GB of characters.

Extremely large integer as a string so that when it tries to convert to BigInt, it should probably overflow or crash.

A single character or string such that the Regex will split the string into an array of size 1.. Then when it tries to read word[1], it crashes due to index out of bounds or invokes undefined behaviour since the array's only index is 0.

I'd say the third option is the most viable and easiest to do.


Too lazy to download the second program or click the links.. Looks fairly simple though.

masterBB

2013-04-19 20:50:52

Clicked all download and link and I think I know what the problems are, if you can't figure it out tomorrow I will help you on IRC.

[XoL]

2013-04-19 21:26:11

From: masterBB
Clicked all download and link and I think I know what the problems are, if you can't figure it out tomorrow I will help you on IRC.


Ok, so it works for you guys. The problem I was having was my .jar file wouldn't open.. awkward lol once I figure that one out I will get back here.. I thought I had to do some weird configurations to make the .jar work.. (glad thats not the assignment lol)

Sorry brain farts all daaayyy

[XoL]

2013-04-22 22:24:18

Sorry for bumping, but where you guys able to figure out a infinite loop for the second one? I tried MANY different combos but can't seem to create one.