Skip to content

Commit

Permalink
Fix code
Browse files Browse the repository at this point in the history
  • Loading branch information
masesdevelopers committed Dec 12, 2024
1 parent c87d533 commit 3a048f8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 32 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
${{ github.workspace }}/tests/native/CreateVM.out
build_container_jnet:
needs: check_changes
needs: [check_changes, build_macos_native]
if: "always() && needs.check_changes.outputs.run_build_windows == 'true'"
runs-on: ubuntu-latest
permissions:
Expand Down Expand Up @@ -183,7 +183,7 @@ jobs:

# Now run "build_windows"
build_windows:
needs: check_changes
needs: [check_changes, build_macos_native]
if: "always() && needs.check_changes.outputs.run_build_windows == 'true'"
# The type of runner that the job will run on
runs-on: windows-2022
Expand Down
50 changes: 20 additions & 30 deletions tests/native/CreateVM.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
#include <iostream>
#include "jni.h"

void print_error(jint ret)
{
switch (ret)
{
case -1: std::cout << "failed - unknown error" << std::endl; return;
case -2: std::cout << "failed - thread detached from the VM" << std::endl; return;
case -3: std::cout << "failed - JNI version error" << std::endl; return;
case -4: std::cout << "failed - not enough memory" << std::endl; return;
case -5: std::cout << "failed - VM already created" << std::endl; return;
case -6: std::cout << "failed - invalid arguments" << std::endl; return;
default: break;
}
}

int main()
{
const int arguments = 4;
Expand All @@ -15,16 +29,8 @@ int main()
jint ret = JNI_GetCreatedJavaVMs(&jvm, 1, &numVms);
if (ret != JNI_OK)
{
switch (ret)
{
case -1: std::cout << "failed - unknown error"; << std::endl; return;
case -2: std::cout << "failed - thread detached from the VM"; << std::endl; return;
case -3: std::cout << "failed - JNI version error"; << std::endl; return;
case -4: std::cout << "failed - not enough memory"; << std::endl; return;
case -5: std::cout << "failed - VM already created"; << std::endl; return;
case -6: std::cout << "failed - invalid arguments"; << std::endl; return;
default: break;
}
print_error(ret);
return 1;
}

if (numVms >= 0)
Expand All @@ -38,16 +44,8 @@ int main()
ret = JNI_GetDefaultJavaVMInitArgs(&vm_args);
if (ret != JNI_OK)
{
switch (ret)
{
case -1: std::cout << "failed - unknown error"; << std::endl; return;
case -2: std::cout << "failed - thread detached from the VM"; << std::endl; return;
case -3: std::cout << "failed - JNI version error"; << std::endl; return;
case -4: std::cout << "failed - not enough memory"; << std::endl; return;
case -5: std::cout << "failed - VM already created"; << std::endl; return;
case -6: std::cout << "failed - invalid arguments"; << std::endl; return;
default: break;
}
print_error(ret);
return 1;
}

JavaVMOption* options = new JavaVMOption[arguments];
Expand All @@ -64,16 +62,8 @@ int main()
ret = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
if (ret != JNI_OK)
{
switch (ret)
{
case -1: std::cout << "failed - unknown error"; << std::endl; return;
case -2: std::cout << "failed - thread detached from the VM"; << std::endl; return;
case -3: std::cout << "failed - JNI version error"; << std::endl; return;
case -4: std::cout << "failed - not enough memory"; << std::endl; return;
case -5: std::cout << "failed - VM already created"; << std::endl; return;
case -6: std::cout << "failed - invalid arguments"; << std::endl; return;
default: break;
}
print_error(ret);
return 1;
}

delete[] options;
Expand Down

0 comments on commit 3a048f8

Please sign in to comment.