[clang] Fixing the tests for the models of getc.

master
Dulma Rodriguez 10 years ago
parent 3ce393f511
commit 34b911c935

@ -1,55 +1,41 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
void crash_getc() {
void crashgetc() {
FILE *f; FILE *f;
int i; int i;
f = fopen("this_file_doesnt_exists", "r");
f=fopen("this_file_doesnt_exists", "r"); i = getc(f);
i =getc(f);
printf("i =%i\n", i); printf("i =%i\n", i);
fclose(f); fclose(f);
} }
void nocrashgetc() { void nocrash_getc() {
FILE *f; FILE *f;
int i; int i;
f = fopen("this_file_doesnt_exists", "r");
f=fopen("this_file_doesnt_exists", "r");
if (f) { if (f) {
i =getc(f); i = getc(f);
printf("i =%i\n", i); printf("i =%i\n", i);
fclose(f); fclose(f);
} }
} }
void crashfgetc() { void crash_fgetc() {
FILE *f; FILE *f;
int i; int i;
f = fopen("this_file_doesnt_exists", "r");
f=fopen("this_file_doesnt_exists", "r"); i = fgetc(f);
i =fgetc(f);
printf("i =%i\n", i); printf("i =%i\n", i);
fclose(f); fclose(f);
} }
void nocrashfgetc() { void nocrash_fgetc() {
FILE *f; FILE *f;
int i; int i;
f = fopen("this_file_doesnt_exists", "r");
f=fopen("this_file_doesnt_exists", "r");
if (f) { if (f) {
i =fgetc(f); i = fgetc(f);
printf("i =%i\n", i); printf("i =%i\n", i);
fclose(f); fclose(f);
} }

@ -6,8 +6,7 @@
package endtoend.c; package endtoend.c;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static utils.matchers.ResultContainsErrorInMethod.contains; import static utils.matchers.ResultContainsExactly.containsExactly;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
@ -20,7 +19,7 @@ import utils.InferResults;
public class NullDereferenceTest2 { public class NullDereferenceTest2 {
public static final String SOURCE_FILE = public static final String SOURCE_FILE =
"null_dereference/get.c"; "null_dereference/getc.c";
public static final String NULL_DEREFERENCE = "NULL_DEREFERENCE"; public static final String NULL_DEREFERENCE = "NULL_DEREFERENCE";
@ -34,31 +33,21 @@ public class NullDereferenceTest2 {
SOURCE_FILE); SOURCE_FILE);
} }
/*
@Test
public void nullDereferenceTest2() throws InterruptedException, IOException, InferException {
assertThat(
"Results should contain null pointer dereference error",
inferResults,
contains(
NULL_DEREFERENCE,
SOURCE_FILE,
"crashgetc"
)
);
}
@Test @Test
public void nullDereferenceTest2_fgetc() throws InterruptedException, IOException, InferException { public void nullDereferenceTest() throws InterruptedException, IOException, InferException {
String[] procedures = {
"crash_getc",
"crash_fgetc",
};
System.out.println(inferResults.toString());
assertThat( assertThat(
"Results should contain null pointer dereference error", "Results should contain null pointer dereference error",
inferResults, inferResults,
contains( containsExactly(
NULL_DEREFERENCE, NULL_DEREFERENCE,
SOURCE_FILE, SOURCE_FILE,
"crashfgetc" procedures
) )
); );
} }
*/
} }

@ -107,6 +107,7 @@ public class InferResults {
for (InferError e : errors) { for (InferError e : errors) {
s = s + "\n" + e.toString(); s = s + "\n" + e.toString();
} }
if (s.length() == 0) return "No results.";
return s; return s;
} }

Loading…
Cancel
Save