Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@ build
.classpath
.project
.settings/
/.gradle/
/gradle/
/gradlew
/gradlew.bat
.gitmodules
src/main/
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,22 @@ git clone https://github.com/stleary/JSON-Java-unit-test.git .
\# Create a directory structure for the JSON-Java code
````
# Windows version
md /s src\org\json
md /s src\main\java\org\json
# *nix version
mkdir -p src/main/java/org/json
````
\# clone JSON-Java
````
git clone https://github.com/stleary/JSON-Java.git src\org\json
#Windows version
git clone https://github.com/stleary/JSON-Java.git src\main\java\org\json

#*Nix version
git clone https://github.com/stleary/JSON-Java.git src/main/java/org/json
````
\# Build, then execute the unit tests and code coverage
````
gradle clean build test jacocoTestReport

````
Unit test results will be in build\reports\tests\index.html<br>
Code coverage will be in build\reports\jacoco\html\index.html
Expand All @@ -55,7 +62,7 @@ When adding a new unit test, don't forget to update <b>JunitTestSuite.java</b>.

<b>The fundamental issues with JSON-Java testing are:</b><br>
* <b>JSONObjects</b> are unordered, making simple string comparison ineffective.
* Comparisons via **equals()** is not currently supported. Neither <b>JSONArray</b> nor <b>JSONObject</b> overrride <b>hashCode()</b> or <b>equals()</b>, so comparison defaults to the <b>Object</b> equals(), which is not useful.
* Comparisons via **equals()** is not currently supported. Neither <b>JSONArray</b> nor <b>JSONObject</b> override <b>hashCode()</b> or <b>equals()</b>, so comparison defaults to the <b>Object</b> equals(), which is not useful.
* Access to the <b>JSONArray</b> and <b>JSONObject</b> internal containers for comparison is not currently available.

<b>General issues with unit testing are:</b><br>
Expand Down
17 changes: 2 additions & 15 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,8 @@ apply plugin: 'jacoco'

sourceSets {
// Uncomment main if you have merged JSON-Java and JSON-Java-unit-test code
main {
java {
srcDir 'src'
exclude 'test/'
}
}
test {
java {
srcDir 'src/test'
exclude 'resources/'
}
resources {
srcDir 'resources'
}
}
main
test
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1564,6 +1564,26 @@ public void wrapObject() {
assertTrue("expected val3", "val3".equals(mapJsonObject.query("/key3")));
}


/**
* RFC 7159 defines control characters to be U+0000 through U+001F. This test verifies that the parser is checking for these in expected ways.
*/
@Test
public void jsonObjectParseControlCharacters(){
for(int i = 0;i<=0x001f;i++){
final String charString = String.valueOf((char)i);
final String source = "{\"key\":\""+charString+"\"}";
try {
JSONObject jo = new JSONObject(source);
assertTrue("Expected "+charString+"("+i+") in the JSON Object but did not find it.",charString.equals(jo.getString("key")));
} catch (JSONException ex) {
assertTrue("Only \\0 (U+0000), \\n (U+000A), and \\r (U+000D) should cause an error. Instead "+charString+"("+i+") caused an error",
i=='\0' || i=='\n' || i=='\r'
);
}
}
}

/**
* Explore how JSONObject handles parsing errors.
*/
Expand Down