Skip to content

Instantly share code, notes, and snippets.

@lptr
Created October 21, 2022 07:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lptr/f45ccdadc1be4d727e3cf3182b0a6915 to your computer and use it in GitHub Desktop.
Save lptr/f45ccdadc1be4d727e3cf3182b0a6915 to your computer and use it in GitHub Desktop.
diff --git a/file-events/src/test/cpp/test_fsnotifier.cpp b/file-events/src/test/cpp/test_fsnotifier.cpp
new file mode 100644
index 0000000..add06ac
--- /dev/null
+++ b/file-events/src/test/cpp/test_fsnotifier.cpp
@@ -0,0 +1,32 @@
+#include "test_fsnotifier.h"
+
+using namespace std;
+
+Server::Server(JNIEnv* env, jobject watcherCallback)
+ : AbstractServer(env, watcherCallback) {
+}
+
+void Server::initializeRunLoop() {
+ // threadLoop = CFRunLoopGetCurrent();
+ // CFRunLoopAddSource(threadLoop, messageSource, kCFRunLoopDefaultMode);
+}
+
+void Server::runLoop() {
+ // CFRunLoopRun();
+}
+
+void Server::shutdownRunLoop() {
+ // CFRunLoopStop(threadLoop);
+}
+
+void Server::registerPaths(const vector<u16string>& paths) {
+}
+
+bool Server::unregisterPaths(const vector<u16string>& paths) {
+ return true;
+}
+
+JNIEXPORT jobject JNICALL
+Java_net_rubygrapefruit_platform_internal_jni_TestFileEventFunctions_startWatcher0(JNIEnv* env, jclass, jobject javaCallback) {
+ return wrapServer(env, new Server(env, javaCallback));
+}
diff --git a/file-events/src/test/headers/test_fsnotifier.h b/file-events/src/test/headers/test_fsnotifier.h
new file mode 100644
index 0000000..255d33b
--- /dev/null
+++ b/file-events/src/test/headers/test_fsnotifier.h
@@ -0,0 +1,21 @@
+#pragma once
+
+#include <unordered_map>
+
+#include "generic_fsnotifier.h"
+#include "net_rubygrapefruit_platform_internal_jni_TestFileEventFunctions.h"
+
+using namespace std;
+
+class Server : public AbstractServer {
+public:
+ Server(JNIEnv* env, jobject watcherCallback);
+
+ virtual void registerPaths(const vector<u16string>& paths) override;
+ virtual bool unregisterPaths(const vector<u16string>& paths) override;
+
+protected:
+ void initializeRunLoop() override;
+ void runLoop() override;
+ void shutdownRunLoop() override;
+};
diff --git a/file-events/src/test/java/net/rubygrapefruit/platform/internal/jni/TestFileEventFunctions.java b/file-events/src/test/java/net/rubygrapefruit/platform/internal/jni/TestFileEventFunctions.java
new file mode 100644
index 0000000..475fed3
--- /dev/null
+++ b/file-events/src/test/java/net/rubygrapefruit/platform/internal/jni/TestFileEventFunctions.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2012 Adam Murdoch
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.rubygrapefruit.platform.internal.jni;
+
+import net.rubygrapefruit.platform.file.FileWatchEvent;
+
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.TimeUnit;
+
+public class TestFileEventFunctions extends AbstractFileEventFunctions<TestFileEventFunctions.TestFileWatcher> {
+ @Override
+ public WatcherBuilder newWatcher(BlockingQueue<FileWatchEvent> eventQueue) {
+ return new WatcherBuilder(eventQueue);
+ }
+
+ public static class TestFileWatcher extends AbstractFileEventFunctions.NativeFileWatcher {
+ public TestFileWatcher(Object server, long startTimeout, TimeUnit startTimeoutUnit, NativeFileWatcherCallback callback) throws InterruptedException {
+ super(server, startTimeout, startTimeoutUnit, callback);
+ }
+ }
+
+ public static class WatcherBuilder extends AbstractWatcherBuilder<TestFileWatcher> {
+ WatcherBuilder(BlockingQueue<FileWatchEvent> eventQueue) {
+ super(eventQueue);
+ }
+
+ @Override
+ protected Object startWatcher(NativeFileWatcherCallback callback) {
+ return startWatcher0(callback);
+ }
+
+ @Override
+ protected TestFileWatcher createWatcher(Object server, long startTimeout, TimeUnit startTimeoutUnit, NativeFileWatcherCallback callback) throws InterruptedException {
+ return new TestFileWatcher(server, startTimeout, startTimeoutUnit, callback);
+ }
+ }
+
+ private static native Object startWatcher0(NativeFileWatcherCallback callback);
+}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment