Commit cd7b742a authored by George Nash's avatar George Nash

Expose oc_random to java to resolve junit issues

Signed-off-by: George Nash's avatarGeorge Nash <george.nash@intel.com>
parent b7baeeb4
Pipeline #433 passed with stage
in 6 minutes and 16 seconds
......@@ -275,6 +275,7 @@ del $(SolutionDir)..\..\..\swig\iotivity-lite-java\src\org\iotivity\oc\*.java</C
<ClCompile Include="..\..\..\..\swig\iotivity-lite-java\jni\oc_iotivity_lite_jni.c" />
<ClCompile Include="..\..\..\..\swig\iotivity-lite-java\jni\oc_obt_wrap.c" />
<ClCompile Include="..\..\..\..\swig\iotivity-lite-java\jni\oc_pki_wrap.c" />
<ClCompile Include="..\..\..\..\swig\iotivity-lite-java\jni\oc_random_wrap.c" />
<ClCompile Include="..\..\..\..\swig\iotivity-lite-java\jni\oc_rep_wrap.c" />
<ClCompile Include="..\..\..\..\swig\iotivity-lite-java\jni\oc_session_events_wrap.c" />
<ClCompile Include="..\..\..\..\swig\iotivity-lite-java\jni\oc_storage_wrap.c" />
......
......@@ -52,6 +52,9 @@
<ClCompile Include="..\..\..\..\swig\iotivity-lite-java\jni\oc_connectivity_wrap.c">
<Filter>c_wrap</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\swig\iotivity-lite-java\jni\oc_random_wrap.c">
<Filter>c_wrap</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Text Include="ReadMe.txt" />
......
......@@ -320,6 +320,21 @@ xcopy /s /y /d /q $(SolutionDir)..\..\..\swig\oc_java\oc\*.java $(SolutionDir)..
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)../../../swig/iotivity-lite-java/jni/%(Filename)_wrap.c;</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(SolutionDir)../../../swig/iotivity-lite-java/jni/%(Filename)_wrap.c;</Outputs>
</CustomBuild>
<CustomBuild Include="..\..\..\..\swig\swig_interfaces\oc_random.i">
<FileType>Document</FileType>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">swig -java -package org.iotivity -outdir $(SolutionDir)../../../swig/iotivity-lite-java/src/org/iotivity/ -D_WIN32 -I$(SolutionDir)../../.. -I$(SolutionDir)../../../port/windows -I$(SolutionDir)../../../include/ -o $(SolutionDir)../../../swig/iotivity-lite-java/jni/%(Filename)_wrap.c %(Identity)</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">swig -java -package org.iotivity -outdir $(SolutionDir)../../../swig/iotivity-lite-java/src/org/iotivity/ -D_WIN32 -I$(SolutionDir)../../.. -I$(SolutionDir)../../../port/windows -I$(SolutionDir)../../../include/ -o $(SolutionDir)../../../swig/iotivity-lite-java/jni/%(Filename)_wrap.c %(Identity)</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">swig -java -package org.iotivity -outdir $(SolutionDir)../../../swig/iotivity-lite-java/src/org/iotivity/ -D_WIN32 -I$(SolutionDir)../../.. -I$(SolutionDir)../../../port/windows -I$(SolutionDir)../../../include/ -o $(SolutionDir)../../../swig/iotivity-lite-java/jni/%(Filename)_wrap.c %(Identity)</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">swig -java -package org.iotivity -outdir $(SolutionDir)../../../swig/iotivity-lite-java/src/org/iotivity/ -D_WIN32 -I$(SolutionDir)../../.. -I$(SolutionDir)../../../port/windows -I$(SolutionDir)../../../include/ -o $(SolutionDir)../../../swig/iotivity-lite-java/jni/%(Filename)_wrap.c %(Identity)</Command>
<Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Building SWIG %(Identity) interface</Message>
<Message Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Building SWIG %(Identity) interface</Message>
<Message Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Building SWIG %(Identity) interface</Message>
<Message Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Building SWIG %(Identity) interface</Message>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)../../../swig/iotivity-lite-java/jni/%(Filename)_wrap.c;</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)../../../swig/iotivity-lite-java/jni/%(Filename)_wrap.c;</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(SolutionDir)../../../swig/iotivity-lite-java/jni/%(Filename)_wrap.c;</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(SolutionDir)../../../swig/iotivity-lite-java/jni/%(Filename)_wrap.c;</Outputs>
</CustomBuild>
<None Include="..\..\..\..\swig\swig_interfaces\oc_ri.i">
<FileType>Document</FileType>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">swig -java -package org.iotivity -outdir $(SolutionDir)../../../swig/iotivity-lite-java/src/org/iotivity/ -D_WIN32 -I$(SolutionDir)../../.. -I$(SolutionDir)../../../port/windows -I$(SolutionDir)../../../include/ -o $(SolutionDir)../../../swig/iotivity-lite-java/jni/%(Filename)_wrap.c %(Identity)</Command>
......
......@@ -93,8 +93,8 @@ ifeq ($(TCP),1)
endif
SRC = oc_api oc_buffer_settings oc_clock oc_cloud oc_collection oc_connectivity \
oc_core_res oc_cred oc_endpoint oc_introspection oc_obt oc_pki oc_rep \
oc_session_events oc_storage oc_uuid
oc_core_res oc_cred oc_endpoint oc_introspection oc_obt oc_pki \
oc_random oc_rep oc_session_events oc_storage oc_uuid
# Swig interfaces source
SWIG_INTERFACE_SRC = $(addsuffix .i, $(SRC))
......
......@@ -245,6 +245,8 @@ public class OCEndpointTest {
@Test
public void test_throw_exception_on_setDi_when_endpoint_null() {
// must call OCRandom.init to initialize the random number for generateUuid
OCRandom.init();
try {
OCUuid testUuid = OCUuidUtil.generateUuid();
OCEndpointUtil.setDi(null, testUuid);
......@@ -253,6 +255,8 @@ public class OCEndpointTest {
assertEquals( e.getClass(), NullPointerException.class);
assertEquals(e.getMessage(), "OCEndpoint cannot be null.");
}
// Restore random number to un-initialized state for other tests
OCRandom.destroy();
}
@Test
......
package org.iotivity;
import static org.junit.Assert.*;
import org.junit.Test;
public class OCRandomTest {
@Test
public void randomValue() {
OCRandom.init();
assertNotEquals(OCRandom.randomValue(), OCRandom.randomValue());
OCRandom.destroy();
}
}
......@@ -8,6 +8,8 @@ public class OCUuidTest {
@Test
public void generateAndConvert() {
// must call OCRandom.init to initialize the random number for generateUuid
OCRandom.init();
OCUuid testUuid = OCUuidUtil.generateUuid();
assertNotNull(testUuid);
String uuid_out = OCUuidUtil.uuidToString(testUuid);
......@@ -18,6 +20,8 @@ public class OCUuidTest {
// OC_UUID_LEN is one character longer than length for the '\0' nul terminating
// character in C
assertEquals(OCUuidUtil.OC_UUID_LEN-1, uuid_out.length());
// Restore random number to un-initialized state for other tests
OCRandom.destroy();
}
@Test
......
......@@ -52,6 +52,15 @@ public class TestRunner {
System.out.println("OCOwnershipTransferMethodsTest tests finished SUCCESSFULLY.");
}
System.out.println("Running OCRandom tests.");
result = junit.run(OCRandomTest.class);
if (result.getFailureCount() > 0) {
System.out.println("OCRandomTest Tests FAILED.");
exit_status = 1;
} else {
System.out.println("OCRandomTest tests finished SUCCESSFULLY.");
}
System.out.println("Running OCRepresentationTest tests.");
result = junit.run(OCRepresentationTest.class);
if (result.getFailureCount() > 0) {
......
/* file oc_random.i */
%module OCRandom
%pragma(java) jniclasscode=%{
static {
try {
System.loadLibrary("iotivity-lite-jni");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load. \n" + e);
System.exit(1);
}
}
%}
%{
#include "port/oc_random.h"
%}
%rename (init) oc_random_init;
%rename (randomValue) oc_random_value;
%rename (destroy) oc_random_destroy;
%include "port/oc_random.h"
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment