mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2024-12-28 18:46:18 +00:00
external: Import jnipp
This commit is contained in:
parent
463330d5d5
commit
bf36c5c522
7
src/external/CMakeLists.txt
vendored
7
src/external/CMakeLists.txt
vendored
|
@ -25,6 +25,13 @@ target_include_directories(xrt-external-glad INTERFACE ${CMAKE_CURRENT_SOURCE_DI
|
|||
add_library(xrt-external-hungarian INTERFACE)
|
||||
target_include_directories(xrt-external-hungarian INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/hungarian)
|
||||
|
||||
# JNIPP
|
||||
if(ANDROID)
|
||||
add_library(xrt-external-jnipp STATIC
|
||||
jnipp/jnipp.cpp)
|
||||
target_include_directories(xrt-external-jnipp PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/jnipp)
|
||||
endif()
|
||||
|
||||
# OpenXR
|
||||
add_library(xrt-external-openxr INTERFACE)
|
||||
target_include_directories(xrt-external-openxr INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/openxr_includes)
|
||||
|
|
258
src/external/jnipp/.gitignore
vendored
Normal file
258
src/external/jnipp/.gitignore
vendored
Normal file
|
@ -0,0 +1,258 @@
|
|||
## Ignore Visual Studio temporary files, build results, and
|
||||
## files generated by popular Visual Studio add-ons.
|
||||
|
||||
# User-specific files
|
||||
*.suo
|
||||
*.user
|
||||
*.userosscache
|
||||
*.sln.docstates
|
||||
|
||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||
*.userprefs
|
||||
|
||||
# Build results
|
||||
[Dd]ebug/
|
||||
[Dd]ebugPublic/
|
||||
[Rr]elease/
|
||||
[Rr]eleases/
|
||||
x64/
|
||||
x86/
|
||||
bld/
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
||||
[Ll]og/
|
||||
|
||||
# Visual Studio 2015 cache/options directory
|
||||
.vs/
|
||||
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||
#wwwroot/
|
||||
|
||||
# MSTest test Results
|
||||
[Tt]est[Rr]esult*/
|
||||
[Bb]uild[Ll]og.*
|
||||
|
||||
# NUNIT
|
||||
*.VisualState.xml
|
||||
TestResult.xml
|
||||
|
||||
# Build Results of an ATL Project
|
||||
[Dd]ebugPS/
|
||||
[Rr]eleasePS/
|
||||
dlldata.c
|
||||
|
||||
# DNX
|
||||
project.lock.json
|
||||
artifacts/
|
||||
|
||||
*_i.c
|
||||
*_p.c
|
||||
*_i.h
|
||||
*.ilk
|
||||
*.meta
|
||||
*.obj
|
||||
*.pch
|
||||
*.pdb
|
||||
*.pgc
|
||||
*.pgd
|
||||
*.rsp
|
||||
*.sbr
|
||||
*.tlb
|
||||
*.tli
|
||||
*.tlh
|
||||
*.tmp
|
||||
*.tmp_proj
|
||||
*.log
|
||||
*.vspscc
|
||||
*.vssscc
|
||||
.builds
|
||||
*.pidb
|
||||
*.svclog
|
||||
*.scc
|
||||
|
||||
# Chutzpah Test files
|
||||
_Chutzpah*
|
||||
|
||||
# Visual C++ cache files
|
||||
ipch/
|
||||
*.aps
|
||||
*.ncb
|
||||
*.opendb
|
||||
*.opensdf
|
||||
*.sdf
|
||||
*.cachefile
|
||||
*.VC.db
|
||||
*.VC.VC.opendb
|
||||
|
||||
# Visual Studio profiler
|
||||
*.psess
|
||||
*.vsp
|
||||
*.vspx
|
||||
*.sap
|
||||
|
||||
# TFS 2012 Local Workspace
|
||||
$tf/
|
||||
|
||||
# Guidance Automation Toolkit
|
||||
*.gpState
|
||||
|
||||
# ReSharper is a .NET coding add-in
|
||||
_ReSharper*/
|
||||
*.[Rr]e[Ss]harper
|
||||
*.DotSettings.user
|
||||
|
||||
# JustCode is a .NET coding add-in
|
||||
.JustCode
|
||||
|
||||
# TeamCity is a build add-in
|
||||
_TeamCity*
|
||||
|
||||
# DotCover is a Code Coverage Tool
|
||||
*.dotCover
|
||||
|
||||
# NCrunch
|
||||
_NCrunch_*
|
||||
.*crunch*.local.xml
|
||||
nCrunchTemp_*
|
||||
|
||||
# MightyMoose
|
||||
*.mm.*
|
||||
AutoTest.Net/
|
||||
|
||||
# Web workbench (sass)
|
||||
.sass-cache/
|
||||
|
||||
# Installshield output folder
|
||||
[Ee]xpress/
|
||||
|
||||
# DocProject is a documentation generator add-in
|
||||
DocProject/buildhelp/
|
||||
DocProject/Help/*.HxT
|
||||
DocProject/Help/*.HxC
|
||||
DocProject/Help/*.hhc
|
||||
DocProject/Help/*.hhk
|
||||
DocProject/Help/*.hhp
|
||||
DocProject/Help/Html2
|
||||
DocProject/Help/html
|
||||
|
||||
# Click-Once directory
|
||||
publish/
|
||||
|
||||
# Publish Web Output
|
||||
*.[Pp]ublish.xml
|
||||
*.azurePubxml
|
||||
# TODO: Comment the next line if you want to checkin your web deploy settings
|
||||
# but database connection strings (with potential passwords) will be unencrypted
|
||||
*.pubxml
|
||||
*.publishproj
|
||||
|
||||
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
||||
# checkin your Azure Web App publish settings, but sensitive information contained
|
||||
# in these scripts will be unencrypted
|
||||
PublishScripts/
|
||||
|
||||
# NuGet Packages
|
||||
*.nupkg
|
||||
# The packages folder can be ignored because of Package Restore
|
||||
**/packages/*
|
||||
# except build/, which is used as an MSBuild target.
|
||||
!**/packages/build/
|
||||
# Uncomment if necessary however generally it will be regenerated when needed
|
||||
#!**/packages/repositories.config
|
||||
# NuGet v3's project.json files produces more ignoreable files
|
||||
*.nuget.props
|
||||
*.nuget.targets
|
||||
|
||||
# Microsoft Azure Build Output
|
||||
csx/
|
||||
*.build.csdef
|
||||
|
||||
# Microsoft Azure Emulator
|
||||
ecf/
|
||||
rcf/
|
||||
|
||||
# Windows Store app package directories and files
|
||||
AppPackages/
|
||||
BundleArtifacts/
|
||||
Package.StoreAssociation.xml
|
||||
_pkginfo.txt
|
||||
|
||||
# Visual Studio cache files
|
||||
# files ending in .cache can be ignored
|
||||
*.[Cc]ache
|
||||
# but keep track of directories ending in .cache
|
||||
!*.[Cc]ache/
|
||||
|
||||
# Others
|
||||
ClientBin/
|
||||
~$*
|
||||
*~
|
||||
*.dbmdl
|
||||
*.dbproj.schemaview
|
||||
*.pfx
|
||||
*.publishsettings
|
||||
node_modules/
|
||||
orleans.codegen.cs
|
||||
|
||||
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||
#bower_components/
|
||||
|
||||
# RIA/Silverlight projects
|
||||
Generated_Code/
|
||||
|
||||
# Backup & report files from converting an old project file
|
||||
# to a newer Visual Studio version. Backup files are not needed,
|
||||
# because we have git ;-)
|
||||
_UpgradeReport_Files/
|
||||
Backup*/
|
||||
UpgradeLog*.XML
|
||||
UpgradeLog*.htm
|
||||
|
||||
# SQL Server files
|
||||
*.mdf
|
||||
*.ldf
|
||||
|
||||
# Business Intelligence projects
|
||||
*.rdl.data
|
||||
*.bim.layout
|
||||
*.bim_*.settings
|
||||
|
||||
# Microsoft Fakes
|
||||
FakesAssemblies/
|
||||
|
||||
# GhostDoc plugin setting file
|
||||
*.GhostDoc.xml
|
||||
|
||||
# Node.js Tools for Visual Studio
|
||||
.ntvs_analysis.dat
|
||||
|
||||
# Visual Studio 6 build log
|
||||
*.plg
|
||||
|
||||
# Visual Studio 6 workspace options file
|
||||
*.opt
|
||||
|
||||
# Visual Studio LightSwitch build output
|
||||
**/*.HTMLClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/ModelManifest.xml
|
||||
**/*.Server/GeneratedArtifacts
|
||||
**/*.Server/ModelManifest.xml
|
||||
_Pvt_Extensions
|
||||
|
||||
# Paket dependency manager
|
||||
.paket/paket.exe
|
||||
paket-files/
|
||||
|
||||
# FAKE - F# Make
|
||||
.fake/
|
||||
|
||||
# JetBrains Rider
|
||||
.idea/
|
||||
*.sln.iml
|
||||
*.out
|
||||
*.o
|
||||
/test
|
||||
|
||||
# Gradle
|
||||
.gradle/
|
23
src/external/jnipp/Android.bp
vendored
Normal file
23
src/external/jnipp/Android.bp
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
|
||||
cc_library_headers {
|
||||
name: "libjnipp-headers",
|
||||
export_include_dirs: ["."],
|
||||
vendor_available: true,
|
||||
}
|
||||
|
||||
cc_library_static {
|
||||
name: "libjnipp",
|
||||
|
||||
srcs: [
|
||||
"jnipp.cpp",
|
||||
],
|
||||
|
||||
cppflags: [ "-fexceptions" ],
|
||||
header_libs: [
|
||||
"libjnipp-headers",
|
||||
],
|
||||
export_header_lib_headers: [
|
||||
"libjnipp-headers"
|
||||
],
|
||||
vendor_available: true,
|
||||
}
|
21
src/external/jnipp/LICENSE
vendored
Normal file
21
src/external/jnipp/LICENSE
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2016 Mitchell Dowd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
107
src/external/jnipp/README.md
vendored
Normal file
107
src/external/jnipp/README.md
vendored
Normal file
|
@ -0,0 +1,107 @@
|
|||
# Java Native Interface for C++
|
||||
|
||||
## Overview
|
||||
|
||||
JNIPP is just a C++ wrapper for the standard Java Native Interface (JNI). It
|
||||
tries to take some of the long-winded annoyance out of integrating your Java
|
||||
and C++ code.
|
||||
|
||||
While this project has so far just been a utility library for my own usage,
|
||||
it seems to have caught the eye of some others who have also been looking for
|
||||
a suitable C++ JNI layer. If you have feature requests, do not hesitate to
|
||||
submit them as Github issues. Please be descriptive in your feature request.
|
||||
The more useful information you provide - along with justification on why it
|
||||
should be implemented - the more likely it is that I will add your feature.
|
||||
|
||||
## Requirements
|
||||
|
||||
To compile you will need:
|
||||
|
||||
- A C++11 compatible compiler
|
||||
- An installation of the Java Development Kit (JDK)
|
||||
- The `JAVA_HOME` environment variable, directed to your JDK installation.
|
||||
|
||||
## Usage
|
||||
|
||||
> For comprehensive examples on how to use *jnipp*, see the `tests` project
|
||||
> in the project source code.
|
||||
|
||||
There are two situations where the Java Native Interface would be needed.
|
||||
|
||||
- A Java application calling C/C++ functions; or
|
||||
- A C/C++ application calling Java methods
|
||||
|
||||
### Calling Java from C++
|
||||
|
||||
The following is an example of calling Java from C++.
|
||||
|
||||
```C++
|
||||
#include <jnipp.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
// An instance of the Java VM needs to be created.
|
||||
jni::Vm vm;
|
||||
|
||||
// Create an instance of java.lang.Integer
|
||||
jni::Class Integer = jni::Class("java/lang/Integer");
|
||||
jni::Object i = Integer.newInstance("1000");
|
||||
|
||||
// Call the `toString` method on that integer
|
||||
std::string str = i.call<std::string>("toString");
|
||||
|
||||
// The Java VM is automatically destroyed when it goes out of scope.
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
### Calling C++ from Java
|
||||
|
||||
Consider a basic Java program:
|
||||
|
||||
```Java
|
||||
package com.example;
|
||||
|
||||
class Demo {
|
||||
public int value;
|
||||
|
||||
public static void main(String[] args) {
|
||||
Demo demo = new Demo();
|
||||
demo.value = 1000;
|
||||
demo.run();
|
||||
}
|
||||
|
||||
public native void run();
|
||||
}
|
||||
```
|
||||
|
||||
A matching C++ library which uses *jnipp* could look like:
|
||||
|
||||
```C++
|
||||
#include <jnipp.h>
|
||||
#include <iostream>
|
||||
|
||||
/*
|
||||
The signature here is defind by the JNI standard, so must be adhered to.
|
||||
Although, to prevent pollution of the global namespace, the JNIEnv and
|
||||
jobject types defind by the standard JNI have been placed into the
|
||||
jni namespace.
|
||||
*/
|
||||
extern "C" void Java_com_example_Demo_run(jni::JNIEnv* env, jni::jobject obj)
|
||||
{
|
||||
// jnipp only needs initialising once, but it doesn't hurt to do it again.
|
||||
jni::init(env);
|
||||
|
||||
// Capture the supplied object.
|
||||
jni::Object demo(obj);
|
||||
|
||||
// Print the contents of the `value` field to stdout.
|
||||
std::cout << demo.get<int>("value") << std::endl;
|
||||
}
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
By default, *jnipp* uses std::runtime_error as the base exception class. If you wish,
|
||||
you can define `JNIPP_EXCEPTION_CLASS` to be the exception class you wish to use, before
|
||||
including `jnipp.h`. It just needs a `const char*` constructor.
|
8
src/external/jnipp/android/AndroidManifest.xml
vendored
Normal file
8
src/external/jnipp/android/AndroidManifest.xml
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- BEGIN_INCLUDE(manifest) -->
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="jnipp"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0">
|
||||
</manifest>
|
||||
<!-- END_INCLUDE(manifest) -->
|
12
src/external/jnipp/android/CMakeLists.txt
vendored
Normal file
12
src/external/jnipp/android/CMakeLists.txt
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 3.4.1)
|
||||
|
||||
GET_FILENAME_COMPONENT(root_dir "../.." ABSOLUTE)
|
||||
|
||||
LINK_DIRECTORIES("${root_dir}/${ANDROID_ABI}")
|
||||
|
||||
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${root_dir}/${ANDROID_ABI}")
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DANDROID_STL=c++_static -std=gnu++11 -fexceptions")
|
||||
|
||||
FILE(GLOB sources ../*.cpp ../common/*.cpp ../android/*.cpp)
|
||||
|
||||
ADD_LIBRARY(jnipp SHARED ${sources})
|
30
src/external/jnipp/build.gradle
vendored
Normal file
30
src/external/jnipp/build.gradle
vendored
Normal file
|
@ -0,0 +1,30 @@
|
|||
apply plugin: 'com.android.library'
|
||||
|
||||
android {
|
||||
compileSdkVersion 26
|
||||
buildToolsVersion '28.0.3'
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 15
|
||||
targetSdkVersion 26
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled = false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt')
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
main {
|
||||
manifest.srcFile 'android/AndroidManifest.xml'
|
||||
}
|
||||
}
|
||||
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
path 'android/CMakeLists.txt'
|
||||
}
|
||||
}
|
||||
}
|
10
src/external/jnipp/dotest.sh
vendored
Executable file
10
src/external/jnipp/dotest.sh
vendored
Executable file
|
@ -0,0 +1,10 @@
|
|||
#!/bin/sh
|
||||
set -e
|
||||
(
|
||||
cd $(dirname $0)
|
||||
export JAVA_HOME=/home/ryan/apps/android-studio/jre/
|
||||
make "$@"
|
||||
if [ -x ./test ]; then
|
||||
./test
|
||||
fi
|
||||
)
|
1531
src/external/jnipp/jnipp.cpp
vendored
Normal file
1531
src/external/jnipp/jnipp.cpp
vendored
Normal file
File diff suppressed because it is too large
Load diff
1036
src/external/jnipp/jnipp.h
vendored
Normal file
1036
src/external/jnipp/jnipp.h
vendored
Normal file
File diff suppressed because it is too large
Load diff
45
src/external/jnipp/jnipp.sln
vendored
Normal file
45
src/external/jnipp/jnipp.sln
vendored
Normal file
|
@ -0,0 +1,45 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 14
|
||||
VisualStudioVersion = 14.0.25420.1
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "jnipp", "jnipp.vcxproj", "{A32D4B7D-7009-4C87-9DE8-D7DB659F5B58}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Files", "Solution Files", "{5A4C5782-6F86-4413-9E19-3F6539DCD835}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
LICENSE = LICENSE
|
||||
makefile = makefile
|
||||
README.md = README.md
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tests", "tests\tests.vcxproj", "{911DB449-3D76-4261-8FFD-9BA508ED1D5B}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{A32D4B7D-7009-4C87-9DE8-D7DB659F5B58}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{A32D4B7D-7009-4C87-9DE8-D7DB659F5B58}.Debug|x64.Build.0 = Debug|x64
|
||||
{A32D4B7D-7009-4C87-9DE8-D7DB659F5B58}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{A32D4B7D-7009-4C87-9DE8-D7DB659F5B58}.Debug|x86.Build.0 = Debug|Win32
|
||||
{A32D4B7D-7009-4C87-9DE8-D7DB659F5B58}.Release|x64.ActiveCfg = Release|x64
|
||||
{A32D4B7D-7009-4C87-9DE8-D7DB659F5B58}.Release|x64.Build.0 = Release|x64
|
||||
{A32D4B7D-7009-4C87-9DE8-D7DB659F5B58}.Release|x86.ActiveCfg = Release|Win32
|
||||
{A32D4B7D-7009-4C87-9DE8-D7DB659F5B58}.Release|x86.Build.0 = Release|Win32
|
||||
{911DB449-3D76-4261-8FFD-9BA508ED1D5B}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{911DB449-3D76-4261-8FFD-9BA508ED1D5B}.Debug|x64.Build.0 = Debug|x64
|
||||
{911DB449-3D76-4261-8FFD-9BA508ED1D5B}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{911DB449-3D76-4261-8FFD-9BA508ED1D5B}.Debug|x86.Build.0 = Debug|Win32
|
||||
{911DB449-3D76-4261-8FFD-9BA508ED1D5B}.Release|x64.ActiveCfg = Release|x64
|
||||
{911DB449-3D76-4261-8FFD-9BA508ED1D5B}.Release|x64.Build.0 = Release|x64
|
||||
{911DB449-3D76-4261-8FFD-9BA508ED1D5B}.Release|x86.ActiveCfg = Release|Win32
|
||||
{911DB449-3D76-4261-8FFD-9BA508ED1D5B}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
149
src/external/jnipp/jnipp.vcxproj
vendored
Normal file
149
src/external/jnipp/jnipp.vcxproj
vendored
Normal file
|
@ -0,0 +1,149 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{A32D4B7D-7009-4C87-9DE8-D7DB659F5B58}</ProjectGuid>
|
||||
<RootNamespace>jnipp</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup />
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(JAVA_HOME)\include;$(JAVA_HOME)\include\win32</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Lib>
|
||||
<AdditionalDependencies>jvm.lib</AdditionalDependencies>
|
||||
</Lib>
|
||||
<Lib>
|
||||
<AdditionalLibraryDirectories>$(JAVA_HOME)\lib</AdditionalLibraryDirectories>
|
||||
</Lib>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(JAVA_HOME)\include;$(JAVA_HOME)\include\win32</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Lib>
|
||||
<AdditionalDependencies>jvm.lib</AdditionalDependencies>
|
||||
</Lib>
|
||||
<Lib>
|
||||
<AdditionalLibraryDirectories>$(JAVA_HOME)\lib</AdditionalLibraryDirectories>
|
||||
</Lib>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(JAVA_HOME)\include;$(JAVA_HOME)\include\win32</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
<Lib>
|
||||
<AdditionalDependencies>jvm.lib</AdditionalDependencies>
|
||||
</Lib>
|
||||
<Lib>
|
||||
<AdditionalLibraryDirectories>$(JAVA_HOME)\lib</AdditionalLibraryDirectories>
|
||||
</Lib>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(JAVA_HOME)\include;$(JAVA_HOME)\include\win32</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
<Lib>
|
||||
<AdditionalDependencies>jvm.lib</AdditionalDependencies>
|
||||
</Lib>
|
||||
<Lib>
|
||||
<AdditionalLibraryDirectories>$(JAVA_HOME)\lib</AdditionalLibraryDirectories>
|
||||
</Lib>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="jnipp.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="jnipp.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
9
src/external/jnipp/jnipp.vcxproj.filters
vendored
Normal file
9
src/external/jnipp/jnipp.vcxproj.filters
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<ClInclude Include="jnipp.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="jnipp.cpp" />
|
||||
</ItemGroup>
|
||||
</Project>
|
32
src/external/jnipp/makefile
vendored
Normal file
32
src/external/jnipp/makefile
vendored
Normal file
|
@ -0,0 +1,32 @@
|
|||
CC=g++
|
||||
|
||||
OS_NAME := linux
|
||||
|
||||
ifeq ($(OS),Windows_NT)
|
||||
OS_NAME := win32
|
||||
RM := del
|
||||
else
|
||||
RM := rm -f
|
||||
UNAME_S := $(shell uname -s)
|
||||
ifeq ($(UNAME_S),Darwin)
|
||||
OS_NAME := darwin
|
||||
endif
|
||||
endif
|
||||
|
||||
JAVA_HOME ?= /usr/lib/jvm/default-java
|
||||
|
||||
CXXFLAGS=-I. -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/$(OS_NAME) -ldl -std=c++11
|
||||
|
||||
SRC=jnipp.o main.o
|
||||
VPATH=tests
|
||||
|
||||
%.o: %.cpp
|
||||
$(CC) -c -o $@ $< $(CXXFLAGS)
|
||||
|
||||
test: $(SRC)
|
||||
$(CC) -o test $(SRC) $(CXXFLAGS)
|
||||
|
||||
clean:
|
||||
-$(RM) $(SRC) test
|
||||
|
||||
.PHONY: clean
|
619
src/external/jnipp/tests/main.cpp
vendored
Normal file
619
src/external/jnipp/tests/main.cpp
vendored
Normal file
|
@ -0,0 +1,619 @@
|
|||
// Project Dependencies
|
||||
#include <jnipp.h>
|
||||
|
||||
// Standard Dependencies
|
||||
#include <cmath>
|
||||
|
||||
// Local Dependencies
|
||||
#include "testing.h"
|
||||
|
||||
/*
|
||||
jni::Vm Tests
|
||||
*/
|
||||
|
||||
|
||||
TEST(Vm_detectsJreInstall)
|
||||
{
|
||||
try
|
||||
{
|
||||
jni::Vm vm;
|
||||
}
|
||||
catch (jni::InitializationException&)
|
||||
{
|
||||
ASSERT(0);
|
||||
return;
|
||||
}
|
||||
|
||||
ASSERT(1);
|
||||
}
|
||||
|
||||
TEST(Vm_notAllowedMultipleVms)
|
||||
{
|
||||
try
|
||||
{
|
||||
jni::Vm firstVm;
|
||||
jni::Vm secondVm; // Throws an exception.
|
||||
}
|
||||
catch (jni::InitializationException&)
|
||||
{
|
||||
ASSERT(1);
|
||||
return;
|
||||
}
|
||||
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
/*
|
||||
jni::Class Tests
|
||||
*/
|
||||
|
||||
|
||||
TEST(Class_findByName_success)
|
||||
{
|
||||
jni::Class cls("java/lang/String");
|
||||
|
||||
ASSERT(!cls.isNull());
|
||||
}
|
||||
|
||||
TEST(Class_findByName_failure)
|
||||
{
|
||||
try
|
||||
{
|
||||
jni::Class cls("does/not/Exist");
|
||||
}
|
||||
catch (jni::NameResolutionException&)
|
||||
{
|
||||
ASSERT(1);
|
||||
return;
|
||||
}
|
||||
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
TEST(Class_getName)
|
||||
{
|
||||
jni::Class cls("java/lang/String");
|
||||
|
||||
ASSERT(cls.getName() == "java.lang.String");
|
||||
}
|
||||
|
||||
TEST(Class_getParent)
|
||||
{
|
||||
jni::Class parent = jni::Class("java/lang/Integer").getParent();
|
||||
|
||||
ASSERT(parent.getName() == "java.lang.Number");
|
||||
}
|
||||
|
||||
TEST(Class_newInstance)
|
||||
{
|
||||
jni::Class Integer("java/lang/Integer");
|
||||
jni::method_t constructor = Integer.getConstructor("(Ljava/lang/String;)V");
|
||||
jni::Object i = Integer.newInstance(constructor, "123");
|
||||
jni::Object str = jni::Class("java/lang/String").newInstance();
|
||||
|
||||
ASSERT(!i.isNull());
|
||||
ASSERT(!str.isNull());
|
||||
}
|
||||
|
||||
TEST(Class_newInstance_withArgs)
|
||||
{
|
||||
jni::Object str1 = jni::Class("java/lang/String").newInstance("Testing...");
|
||||
jni::Object str2 = jni::Class("java/lang/String").newInstance(L"Testing...");
|
||||
|
||||
ASSERT(!str1.isNull());
|
||||
ASSERT(!str2.isNull());
|
||||
}
|
||||
|
||||
TEST(Class_getStaticField)
|
||||
{
|
||||
jni::field_t field = jni::Class("java/lang/Integer").getStaticField("MAX_VALUE", "I");
|
||||
|
||||
ASSERT(field);
|
||||
}
|
||||
|
||||
TEST(Class_getMethod)
|
||||
{
|
||||
jni::method_t method1 = jni::Class("java/lang/Integer").getMethod("intValue", "()I");
|
||||
jni::method_t method2 = jni::Class("java/lang/Integer").getMethod("intValue()I");
|
||||
|
||||
ASSERT(method1);
|
||||
ASSERT(method2);
|
||||
}
|
||||
|
||||
TEST(Class_getStaticMethod)
|
||||
{
|
||||
jni::method_t method = jni::Class("java/lang/Integer").getStaticMethod("compare", "(II)I");
|
||||
|
||||
ASSERT(method);
|
||||
}
|
||||
|
||||
TEST(Class_call)
|
||||
{
|
||||
jni::Class Integer("java/lang/Math");
|
||||
|
||||
double x = Integer.call<double>("random");
|
||||
|
||||
ASSERT(x >= 0.0);
|
||||
ASSERT(x < 1.0);
|
||||
}
|
||||
|
||||
TEST(Class_get_staticField)
|
||||
{
|
||||
jni::Class Integer("java/lang/Integer");
|
||||
jni::field_t field = Integer.getStaticField("SIZE", "I");
|
||||
|
||||
ASSERT(Integer.get<int>(field) == 32);
|
||||
}
|
||||
|
||||
TEST(Class_get_staticField_byName)
|
||||
{
|
||||
jni::Class Integer("java/lang/Integer");
|
||||
jni::Class Character("java/lang/Character");
|
||||
jni::Class Short("java/lang/Short");
|
||||
jni::Class Long("java/lang/Long");
|
||||
jni::Class Float("java/lang/Float");
|
||||
jni::Class Double("java/lang/Double");
|
||||
|
||||
ASSERT(Short.get<short>("MAX_VALUE") == short(0x7FFF));
|
||||
ASSERT(Character.get<wchar_t>("MAX_VALUE") == L'\xFFFF')
|
||||
ASSERT(Integer.get<int>("MAX_VALUE") == int(0x7FFFFFFF));
|
||||
ASSERT(Long.get<long long>("MAX_VALUE") == (long long) (0x7FFFFFFFFFFFFFFF));
|
||||
ASSERT(std::isnan(Float.get<float>("NaN")));
|
||||
ASSERT(std::isnan(Double.get<double>("NaN")));
|
||||
}
|
||||
|
||||
TEST(Class_getConstructor)
|
||||
{
|
||||
jni::Class Integer("java/lang/Integer");
|
||||
jni::method_t constructor = Integer.getConstructor("(Ljava/lang/String;)V");
|
||||
|
||||
ASSERT(constructor);
|
||||
}
|
||||
|
||||
TEST(Class_call_staticMethod)
|
||||
{
|
||||
jni::Class Integer("java/lang/Integer");
|
||||
jni::method_t method = Integer.getStaticMethod("parseInt", "(Ljava/lang/String;)I");
|
||||
|
||||
int i = Integer.call<int>(method, "1000");
|
||||
|
||||
ASSERT(i == 1000);
|
||||
}
|
||||
|
||||
TEST(Class_call_staticMethod_byName)
|
||||
{
|
||||
int i = jni::Class("java/lang/Integer").call<int>("parseInt", "1000");
|
||||
bool b = jni::Class("java/lang/Boolean").call<bool>("parseBoolean", "true");
|
||||
wchar_t c = jni::Class("java/lang/Character").call<wchar_t>("toLowerCase", L'X');
|
||||
short s = jni::Class("java/lang/Short").call<short>("parseShort", "1000");
|
||||
long long l = jni::Class("java/lang/Long").call<long long>("parseLong", "1000");
|
||||
float f = jni::Class("java/lang/Float").call<float>("parseFloat", "123.0");
|
||||
double d = jni::Class("java/lang/Double").call<double>("parseDouble", "123.0");
|
||||
|
||||
ASSERT(i == 1000);
|
||||
ASSERT(b == true);
|
||||
ASSERT(c == L'x');
|
||||
ASSERT(s == 1000);
|
||||
ASSERT(l == 1000);
|
||||
ASSERT(f == 123.0); // Warning: floating point comparison.
|
||||
ASSERT(d == 123.0); // Warning: floating point comparison.
|
||||
}
|
||||
|
||||
/*
|
||||
jni::Object Tests
|
||||
*/
|
||||
|
||||
|
||||
TEST(Object_defaultConstructor_isNull)
|
||||
{
|
||||
jni::Object o;
|
||||
|
||||
ASSERT(o.isNull());
|
||||
}
|
||||
|
||||
TEST(Object_copyConstructorIsSameObject)
|
||||
{
|
||||
jni::Object a = jni::Class("java/lang/String").newInstance();
|
||||
jni::Object b = a;
|
||||
|
||||
ASSERT(a == b);
|
||||
}
|
||||
|
||||
TEST(Object_moveConstructor)
|
||||
{
|
||||
jni::Object a = jni::Class("java/lang/String").newInstance();
|
||||
jni::Object b = std::move(a);
|
||||
|
||||
ASSERT(a.isNull());
|
||||
ASSERT(!b.isNull());
|
||||
}
|
||||
|
||||
TEST(Object_copyAssignmentOperator)
|
||||
{
|
||||
jni::Object a = jni::Class("java/lang/String").newInstance();
|
||||
jni::Object b = jni::Class("java/lang/Integer").newInstance(0);
|
||||
|
||||
a = b;
|
||||
|
||||
ASSERT(a == b);
|
||||
}
|
||||
|
||||
TEST(Object_moveAssignmentOperator)
|
||||
{
|
||||
jni::Object a = jni::Class("java/lang/String").newInstance();
|
||||
jni::Object b = jni::Class("java/lang/Integer").newInstance(0);
|
||||
|
||||
a = std::move(b);
|
||||
|
||||
ASSERT(!a.isNull());
|
||||
ASSERT(b.isNull());
|
||||
}
|
||||
|
||||
TEST(Object_call)
|
||||
{
|
||||
jni::Class Integer("java/lang/Integer");
|
||||
jni::method_t intValue = Integer.getMethod("intValue", "()I");
|
||||
jni::Object i = Integer.newInstance(100);
|
||||
|
||||
ASSERT(i.call<int>(intValue) == 100);
|
||||
}
|
||||
|
||||
TEST(Object_call_byName)
|
||||
{
|
||||
jni::Object i = jni::Class("java/lang/Integer").newInstance(100);
|
||||
jni::Object b = jni::Class("java/lang/Boolean").newInstance(true);
|
||||
jni::Object s = jni::Class("java/lang/Short").newInstance(short(100));
|
||||
jni::Object l = jni::Class("java/lang/Long").newInstance(100LL);
|
||||
jni::Object f = jni::Class("java/lang/Float").newInstance(100.0f);
|
||||
jni::Object d = jni::Class("java/lang/Double").newInstance(100.0);
|
||||
|
||||
ASSERT(i.call<int>("intValue") == 100);
|
||||
ASSERT(s.call<short>("shortValue") == 100);
|
||||
ASSERT(b.call<bool>("booleanValue") == true);
|
||||
ASSERT(l.call<long long>("longValue") == 100LL);
|
||||
ASSERT(f.call<float>("floatValue") == 100.0f); // Warning: Floating point comparison.
|
||||
ASSERT(d.call<double>("doubleValue") == 100.0); // Warning: Floating point comparison.
|
||||
ASSERT(i.call<std::wstring>("toString") == L"100");
|
||||
ASSERT(i.call<std::string>("toString") == "100");
|
||||
}
|
||||
|
||||
TEST(Object_call_withArgs)
|
||||
{
|
||||
jni::Class String("java/lang/String");
|
||||
jni::method_t charAt = String.getMethod("charAt", "(I)C");
|
||||
jni::Object str = String.newInstance("Testing");
|
||||
|
||||
ASSERT(str.call<wchar_t>(charAt, 1) == L'e');
|
||||
}
|
||||
|
||||
TEST(Object_call_byNameWithArgs)
|
||||
{
|
||||
jni::Object str = jni::Class("java/lang/String").newInstance("Testing");
|
||||
jni::Object str2 = jni::Class("java/lang/String").newInstance(L"Testing");
|
||||
|
||||
ASSERT(str.call<wchar_t>("charAt", 1) == L'e');
|
||||
ASSERT(str2.call<wchar_t>("charAt", 1) == L'e');
|
||||
}
|
||||
|
||||
TEST(Object_makeLocalReference)
|
||||
{
|
||||
jni::Object str = jni::Class("java/lang/String").newInstance("Testing");
|
||||
|
||||
jni::jobject local = str.makeLocalReference();
|
||||
ASSERT(local != nullptr);
|
||||
ASSERT(local != str.getHandle());
|
||||
|
||||
jni::Object fromLocal(local, jni::Object::DeleteLocalInput);
|
||||
ASSERT(!fromLocal.isNull());
|
||||
ASSERT(str == fromLocal);
|
||||
}
|
||||
|
||||
/*
|
||||
jni::Enum Tests
|
||||
*/
|
||||
|
||||
|
||||
TEST(Enum_get)
|
||||
{
|
||||
jni::Class Thread("java/lang/Thread");
|
||||
jni::Enum State("java/lang/Thread$State");
|
||||
jni::method_t currentThread = Thread.getStaticMethod("currentThread", "()Ljava/lang/Thread;");
|
||||
jni::method_t getState = Thread.getMethod("getState", "()Ljava/lang/Thread$State;");
|
||||
|
||||
jni::Object thread = Thread.call<jni::Object>(currentThread);
|
||||
jni::Object state = thread.call<jni::Object>(getState);
|
||||
|
||||
ASSERT(state == State.get("RUNNABLE"));
|
||||
}
|
||||
|
||||
/*
|
||||
jni::Array Tests
|
||||
*/
|
||||
|
||||
TEST(Array_defaultConstructor)
|
||||
{
|
||||
jni::Array<int> a;
|
||||
|
||||
ASSERT(a.getLength() == 0);
|
||||
ASSERT(a.isNull());
|
||||
}
|
||||
|
||||
TEST(Array_constructor)
|
||||
{
|
||||
jni::Array<int> a(10);
|
||||
|
||||
ASSERT(a.getLength() == 10);
|
||||
ASSERT(!a.isNull());
|
||||
}
|
||||
|
||||
TEST(Array_constructor_eachType)
|
||||
{
|
||||
jni::Array<bool> b(10);
|
||||
jni::Array<wchar_t> c(10);
|
||||
jni::Array<short> s(10);
|
||||
jni::Array<int> i(10);
|
||||
jni::Array<long long> l(10);
|
||||
jni::Array<float> f(10);
|
||||
jni::Array<double> d(10);
|
||||
jni::Array<std::string> str(10);
|
||||
jni::Array<std::wstring> wstr(10);
|
||||
jni::Array<jni::Object> obj(10);
|
||||
jni::Array<jni::Object> obj2(10, jni::Class("java/lang/Integer"));
|
||||
|
||||
jni::Object* objs[] = { &b, &c, &s, &i, &l, &f, &d, &str, &wstr, &obj, &obj2 };
|
||||
|
||||
for (auto o : objs)
|
||||
ASSERT(!o->isNull());
|
||||
}
|
||||
|
||||
TEST(Array_constructor_withType)
|
||||
{
|
||||
jni::Array<jni::Object> a(10, jni::Class("java/lang/Integer"));
|
||||
|
||||
ASSERT(a.getLength() == 10);
|
||||
ASSERT(!a.isNull());
|
||||
}
|
||||
|
||||
TEST(Array_copyConstructor)
|
||||
{
|
||||
jni::Array<int> a(10);
|
||||
jni::Array<int> b = a;
|
||||
|
||||
ASSERT(a == b);
|
||||
}
|
||||
|
||||
TEST(Array_moveConstructor)
|
||||
{
|
||||
jni::Array<int> a(10);
|
||||
jni::Array<int> b = std::move(a);
|
||||
|
||||
ASSERT(a.isNull());
|
||||
ASSERT(!b.isNull());
|
||||
}
|
||||
|
||||
TEST(Array_copyAssignmentOperator)
|
||||
{
|
||||
jni::Array<int> a(10);
|
||||
jni::Array<int> b(11);
|
||||
|
||||
a = b;
|
||||
|
||||
ASSERT(a == b);
|
||||
}
|
||||
|
||||
TEST(Array_moveAssignmentOperator)
|
||||
{
|
||||
jni::Array<int> a(10);
|
||||
jni::Array<int> b(11);
|
||||
|
||||
a = std::move(b);
|
||||
|
||||
ASSERT(!a.isNull());
|
||||
ASSERT(b.isNull());
|
||||
}
|
||||
|
||||
TEST(Array_getElement_defaultValue)
|
||||
{
|
||||
jni::Array<int> a(10);
|
||||
jni::Array<std::string> s(10);
|
||||
|
||||
ASSERT(a.getElement(0) == 0);
|
||||
ASSERT(s.getElement(0).length() == 0);
|
||||
}
|
||||
|
||||
TEST(Array_getElement_indexException)
|
||||
{
|
||||
jni::Array<int> a(10);
|
||||
|
||||
try
|
||||
{
|
||||
int result = a.getElement(1000);
|
||||
ASSERT(0);
|
||||
}
|
||||
catch (jni::Exception&)
|
||||
{
|
||||
ASSERT(1);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Array_setElement_basicType)
|
||||
{
|
||||
jni::Array<int> a(10);
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
a.setElement(i, i);
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
ASSERT(a.getElement(i) == i);
|
||||
}
|
||||
|
||||
TEST(Array_setElement_string)
|
||||
{
|
||||
jni::Array<std::wstring> a(10);
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
a.setElement(i, std::to_wstring(i));
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
ASSERT(a.getElement(i) == std::to_wstring(i));
|
||||
}
|
||||
|
||||
TEST(Array_setElement_indexException)
|
||||
{
|
||||
jni::Array<std::string> s(10);
|
||||
|
||||
try
|
||||
{
|
||||
auto result = s.getElement(1000);
|
||||
ASSERT(0);
|
||||
}
|
||||
catch (jni::Exception&)
|
||||
{
|
||||
ASSERT(1);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Argument Type Tests
|
||||
*/
|
||||
|
||||
|
||||
TEST(Arg_bool)
|
||||
{
|
||||
std::string str1 = jni::Class("java/lang/String").call<std::string>("valueOf", true);
|
||||
std::wstring str2 = jni::Class("java/lang/String").call<std::wstring>("valueOf", true);
|
||||
|
||||
ASSERT(str1 == "true");
|
||||
ASSERT(str2 == L"true");
|
||||
}
|
||||
|
||||
TEST(Arg_wchar)
|
||||
{
|
||||
std::string str1 = jni::Class("java/lang/String").call<std::string>("valueOf", L'X');
|
||||
std::wstring str2 = jni::Class("java/lang/String").call<std::wstring>("valueOf", L'X');
|
||||
|
||||
ASSERT(str1 == "X");
|
||||
ASSERT(str2 == L"X");
|
||||
}
|
||||
|
||||
TEST(Arg_double)
|
||||
{
|
||||
std::string str1 = jni::Class("java/lang/String").call<std::string>("valueOf", 123.0);
|
||||
std::wstring str2 = jni::Class("java/lang/String").call<std::wstring>("valueOf", 123.0);
|
||||
|
||||
ASSERT(str1 == "123.0");
|
||||
ASSERT(str2 == L"123.0");
|
||||
}
|
||||
|
||||
TEST(Arg_float)
|
||||
{
|
||||
std::string str1 = jni::Class("java/lang/String").call<std::string>("valueOf", 123.0f);
|
||||
std::wstring str2 = jni::Class("java/lang/String").call<std::wstring>("valueOf", 123.0f);
|
||||
|
||||
ASSERT(str1 == "123.0");
|
||||
ASSERT(str2 == L"123.0");
|
||||
}
|
||||
|
||||
TEST(Arg_int)
|
||||
{
|
||||
std::string str1 = jni::Class("java/lang/String").call<std::string>("valueOf", 123);
|
||||
std::wstring str2 = jni::Class("java/lang/String").call<std::wstring>("valueOf", 123);
|
||||
|
||||
ASSERT(str1 == "123");
|
||||
ASSERT(str2 == L"123");
|
||||
}
|
||||
|
||||
TEST(Arg_longLong)
|
||||
{
|
||||
std::string str1 = jni::Class("java/lang/String").call<std::string>("valueOf", 123LL);
|
||||
std::wstring str2 = jni::Class("java/lang/String").call<std::wstring>("valueOf", 123LL);
|
||||
|
||||
ASSERT(str1 == "123");
|
||||
ASSERT(str2 == L"123");
|
||||
}
|
||||
|
||||
TEST(Arg_Object)
|
||||
{
|
||||
jni::Object str1 = jni::Class("java/lang/String").newInstance("123");
|
||||
int i = jni::Class("java/lang/Integer").call<int>("parseInt", str1);
|
||||
|
||||
ASSERT(i == 123);
|
||||
}
|
||||
|
||||
TEST(Arg_ObjectPtr)
|
||||
{
|
||||
jni::Object str1 = jni::Class("java/lang/String").newInstance("123");
|
||||
int i = jni::Class("java/lang/Integer").call<int>("parseInt", &str1);
|
||||
|
||||
ASSERT(i == 123);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
// jni::Vm Tests
|
||||
RUN_TEST(Vm_detectsJreInstall);
|
||||
RUN_TEST(Vm_notAllowedMultipleVms);
|
||||
|
||||
{
|
||||
jni::Vm vm;
|
||||
|
||||
// jni::Class Tests
|
||||
RUN_TEST(Class_findByName_success);
|
||||
RUN_TEST(Class_findByName_failure);
|
||||
RUN_TEST(Class_getName);
|
||||
RUN_TEST(Class_getParent);
|
||||
RUN_TEST(Class_newInstance);
|
||||
RUN_TEST(Class_newInstance_withArgs);
|
||||
RUN_TEST(Class_getStaticField);
|
||||
RUN_TEST(Class_getMethod);
|
||||
RUN_TEST(Class_getStaticMethod);
|
||||
RUN_TEST(Class_call);
|
||||
RUN_TEST(Class_get_staticField);
|
||||
RUN_TEST(Class_get_staticField_byName);
|
||||
RUN_TEST(Class_call_staticMethod_byName);
|
||||
RUN_TEST(Class_getConstructor);
|
||||
|
||||
// jni::Object Tests
|
||||
RUN_TEST(Object_defaultConstructor_isNull);
|
||||
RUN_TEST(Object_copyConstructorIsSameObject);
|
||||
RUN_TEST(Object_moveConstructor);
|
||||
RUN_TEST(Object_copyAssignmentOperator);
|
||||
RUN_TEST(Object_moveAssignmentOperator);
|
||||
RUN_TEST(Object_call);
|
||||
RUN_TEST(Object_call_byName);
|
||||
RUN_TEST(Object_call_withArgs);
|
||||
RUN_TEST(Object_call_byNameWithArgs);
|
||||
RUN_TEST(Object_makeLocalReference);
|
||||
|
||||
// jni::Enum Tests
|
||||
RUN_TEST(Enum_get);
|
||||
|
||||
// jni::Array Tests
|
||||
RUN_TEST(Array_defaultConstructor);
|
||||
RUN_TEST(Array_constructor);
|
||||
RUN_TEST(Array_constructor_eachType);
|
||||
RUN_TEST(Array_constructor_withType);
|
||||
RUN_TEST(Array_copyConstructor);
|
||||
RUN_TEST(Array_moveConstructor);
|
||||
RUN_TEST(Array_getElement_defaultValue);
|
||||
RUN_TEST(Array_getElement_indexException);
|
||||
RUN_TEST(Array_setElement_basicType);
|
||||
RUN_TEST(Array_setElement_string);
|
||||
RUN_TEST(Array_setElement_indexException);
|
||||
|
||||
// Argument Type Tests
|
||||
RUN_TEST(Arg_bool);
|
||||
RUN_TEST(Arg_wchar);
|
||||
RUN_TEST(Arg_double);
|
||||
RUN_TEST(Arg_float);
|
||||
RUN_TEST(Arg_int);
|
||||
RUN_TEST(Arg_longLong);
|
||||
RUN_TEST(Arg_Object);
|
||||
RUN_TEST(Arg_ObjectPtr);
|
||||
}
|
||||
|
||||
std::cout << "Press a key to continue..." << std::endl;
|
||||
std::cin.get();
|
||||
return 0;
|
||||
}
|
||||
|
33
src/external/jnipp/tests/testing.h
vendored
Normal file
33
src/external/jnipp/tests/testing.h
vendored
Normal file
|
@ -0,0 +1,33 @@
|
|||
#ifndef _TESTING_H_
|
||||
#define _TESTING_H_ 1
|
||||
|
||||
// Standard Dependencies
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
#ifdef ASSERT
|
||||
# undef ASSERT
|
||||
#endif
|
||||
|
||||
/** Run the test with the given name. */
|
||||
#define RUN_TEST(TestName) { \
|
||||
bool __test_result = true; \
|
||||
std::cout << "Executing test " << std::left << std::setw(40) << #TestName; \
|
||||
TestName(__test_result); \
|
||||
std::cout << "=> " << (__test_result ? "Success" : "Fail") << std::endl; \
|
||||
}
|
||||
|
||||
/** Define a test with the given name. */
|
||||
#define TEST(TestName) \
|
||||
void TestName(bool& __test_result)
|
||||
|
||||
/** Ensures the given condition passes for the test to pass. */
|
||||
#define ASSERT(condition) { \
|
||||
if (!(condition)) { \
|
||||
__test_result = false; \
|
||||
return; \
|
||||
} \
|
||||
}
|
||||
|
||||
#endif // _TESTING_H_
|
||||
|
130
src/external/jnipp/tests/tests.vcxproj
vendored
Normal file
130
src/external/jnipp/tests/tests.vcxproj
vendored
Normal file
|
@ -0,0 +1,130 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{911DB449-3D76-4261-8FFD-9BA508ED1D5B}</ProjectGuid>
|
||||
<RootNamespace>tests</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup />
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\jnipp.vcxproj">
|
||||
<Project>{a32d4b7d-7009-4c87-9de8-d7db659f5b58}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="testing.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
9
src/external/jnipp/tests/tests.vcxproj.filters
vendored
Normal file
9
src/external/jnipp/tests/tests.vcxproj.filters
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="testing.h" />
|
||||
</ItemGroup>
|
||||
</Project>
|
Loading…
Reference in a new issue