Skip to content

Commit bbd4843

Browse files
committed
add test_call_https_java
1 parent 5cc83ce commit bbd4843

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

src/network.c

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@
1313
#include "utils.h"
1414
#include "curl/curl.h"
1515
#include "cloudsync_private.h"
16-
#include <stdio.h>
17-
#include <android/log.h>
18-
#include <jni.h>
19-
#include <stdlib.h>
20-
#include "call_java.h"
2116

2217
#define CLOUDSYNC_ENDPOINT_PREFIX "v1/cloudsync"
2318
#define CLOUDSYNC_ENDPOINT_UPLOAD "upload"
@@ -459,18 +454,6 @@ void cloudsync_network_init (sqlite3_context *context, int argc, sqlite3_value *
459454
// save site_id string representation: 01957493c6c07e14803727e969f1d2cc
460455
cloudsync_uuid_v7_stringify(site_id, data->site_id, false);
461456

462-
JNIEnv* env = getEnv();
463-
if (!env) {
464-
sqlite3_result_error(context, "Could not get JNIEnv", -1);
465-
return;
466-
}
467-
468-
const char* javaResult = call_https_java(env);
469-
if (javaResult) {
470-
printf("Got from Java: %s\n", javaResult);
471-
__android_log_print(ANDROID_LOG_INFO, "MyNativeCode", "Got from Java: %s", javaResult);
472-
free((void*)javaResult);
473-
}
474457
// connection string is something like:
475458
// https://UUID.g5.sqlite.cloud:443/chinook.sqlite?apikey=hWDanFolRT9WDK0p54lufNrIyfgLZgtMw6tb6fbPmpo
476459
// or https://UUID.g5.sqlite.cloud:443/chinook.sqlite

test/unit.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include "dbutils.h"
2424
#include "cloudsync.h"
2525
#include "cloudsync_private.h"
26+
#include <jni.h>
27+
#include "call_java.h"
2628

2729
// declared only if macro CLOUDSYNC_UNITTEST is defined
2830
extern char *OUT_OF_MEMORY_BUFFER;
@@ -3273,6 +3275,24 @@ bool do_test_alter(int nclients, int alter_version, bool print_result, bool clea
32733275
return result;
32743276
}
32753277

3278+
bool test_call_https_java(void) {
3279+
JNIEnv* env = getEnv();
3280+
if (!env) {
3281+
printf("Could not get JNIEnv\n");
3282+
return false;
3283+
}
3284+
3285+
const char* javaResult = call_https_java(env);
3286+
if (javaResult) {
3287+
printf("Got from Java: %s\n", javaResult);
3288+
free((void*)javaResult);
3289+
return true;
3290+
} else {
3291+
printf("call_https_java returned NULL\n");
3292+
return false;
3293+
}
3294+
}
3295+
32763296
// MARK: -
32773297

32783298
int test_report(const char *description, bool result){
@@ -3341,7 +3361,8 @@ int main(int argc, const char * argv[]) {
33413361
result += test_report("Test Alter Table 1:", do_test_alter(3, 1, print_result, cleanup_databases));
33423362
result += test_report("Test Alter Table 2:", do_test_alter(3, 2, print_result, cleanup_databases));
33433363
result += test_report("Test Alter Table 3:", do_test_alter(3, 3, print_result, cleanup_databases));
3344-
3364+
result += test_report("JNI call_https_java Test:", test_call_https_java());
3365+
33453366
finalize:
33463367
printf("\n");
33473368
if (rc != SQLITE_OK) printf("%s (%d)\n", (db) ? sqlite3_errmsg(db) : "N/A", rc);

0 commit comments

Comments
 (0)