-
Notifications
You must be signed in to change notification settings - Fork 529
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Java] Start to introduce property based testing (PBT).
In this commit, I've: 1. Added a test dependency on JQwik. 2. Added a JQwik-based generator of arbitrary valid SBE message schemas. This generator exercises a lot of possibilities but not all. In particular, it is missing the generation of constants, min/max, and custom offsets. 3. Added a test that shows the parser parses any arbitrary SBE message schema. Why have I introduced PBT? My aim is to eventually test (an approximation of) the following property: ``` ∀ msgSchema ∈ PossibleMessageSchemas, ∀ bytes ∈ PossibleValidValues(msgSchema), DtoEncode(DtoDecode(bytes)) = bytes ``` I.e., that `DtoEncode` is the inverse of `DtoDecode` and that it preserves the information in an encoded message.
- Loading branch information
Showing
5 changed files
with
848 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
sbe-tool/src/test/java/uk/co/real_logic/sbe/properties/ParserPropertyTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright 2013-2023 Real Logic Limited. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package uk.co.real_logic.sbe.properties; | ||
|
||
import net.jqwik.api.Arbitrary; | ||
import net.jqwik.api.ForAll; | ||
import net.jqwik.api.Property; | ||
import net.jqwik.api.Provide; | ||
import uk.co.real_logic.sbe.xml.ParserOptions; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.InputStream; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
import static uk.co.real_logic.sbe.xml.XmlSchemaParser.parse; | ||
|
||
public class ParserPropertyTest | ||
{ | ||
@Property | ||
void shouldParseAnyValidSchema(@ForAll("schemas") final SchemaDomain.MessageSchema schema) throws Exception | ||
{ | ||
final String xml = XmlSchemaWriter.writeString(schema); | ||
try (InputStream in = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8))) | ||
{ | ||
parse(in, ParserOptions.DEFAULT); | ||
} | ||
} | ||
|
||
@Provide | ||
Arbitrary<SchemaDomain.MessageSchema> schemas() | ||
{ | ||
return SchemaDomain.MessageSchema.arbitrary(); | ||
} | ||
} |
Oops, something went wrong.