-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from marc-christian-schulze/default_values
Default values
- Loading branch information
Showing
5 changed files
with
131 additions
and
16 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
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
38 changes: 38 additions & 0 deletions
38
structs4java-maven-plugin-test/src/main/structs/default-values.structs
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,38 @@ | ||
package org.structs4java.example.tests.defaultvalues; | ||
|
||
struct StructWithIntegerDefaultValue { | ||
uint8_t int8 = 1; | ||
uint16_t int16 = 2; | ||
uint32_t int32 = 3; | ||
uint64_t int64 = 4; | ||
} | ||
|
||
struct StructWithFloatDefaultValue { | ||
float f = 1.0; | ||
double d = 2.0; | ||
} | ||
|
||
struct StructWithStringDefaultValue { | ||
char str[] = "default"; | ||
} | ||
|
||
enum Int8Enum : uint8_t { | ||
A = 0x01, | ||
B = 0x02, | ||
C = 0x03 | ||
} | ||
|
||
struct StructWithBitfield { | ||
bitfield uint16_t { | ||
boolean b : 1; | ||
uint8_t int8 : 2; | ||
uint16_t int16 : 2; | ||
uint32_t int32 : 2; | ||
uint64_t int64 : 2; | ||
Int8Enum int8Enum : 7; | ||
} | ||
} | ||
|
||
struct StructWithEnum { | ||
Int8Enum int8Enum = Int8Enum.B; | ||
} |
36 changes: 36 additions & 0 deletions
36
...java-maven-plugin-test/src/test/java/org/structs4java/example/tests/DefaultValueTest.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,36 @@ | ||
package org.structs4java.example.tests; | ||
|
||
import org.junit.Test; | ||
import org.structs4java.example.tests.defaultvalues.*; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class DefaultValueTest { | ||
@Test | ||
public void testStructWithIntegerDefaultValue() { | ||
StructWithIntegerDefaultValue struct = new StructWithIntegerDefaultValue(); | ||
assertEquals(1, struct.getInt8()); | ||
assertEquals(2, struct.getInt16()); | ||
assertEquals(3, struct.getInt32()); | ||
assertEquals(4, struct.getInt64()); | ||
} | ||
|
||
@Test | ||
public void testStructWithFloatDefaultValue() { | ||
StructWithFloatDefaultValue struct = new StructWithFloatDefaultValue(); | ||
assertEquals(1.0, struct.getF(), 0.001); | ||
assertEquals(2.0, struct.getD(), 0.001); | ||
} | ||
|
||
@Test | ||
public void testStructWithStringDefaultValue() { | ||
StructWithStringDefaultValue struct = new StructWithStringDefaultValue(); | ||
assertEquals("default", struct.getStr()); | ||
} | ||
|
||
@Test | ||
public void testStructWithEnumDefaultValue() { | ||
StructWithEnum struct = new StructWithEnum(); | ||
assertEquals(Int8Enum.B, struct.getInt8Enum()); | ||
} | ||
} |