diff --git a/test/arraybuffer.cc b/test/array_buffer.cc similarity index 62% rename from test/arraybuffer.cc rename to test/array_buffer.cc index 4a1b2a34e..2b07bd250 100644 --- a/test/arraybuffer.cc +++ b/test/array_buffer.cc @@ -27,7 +27,8 @@ Value CreateBuffer(const CallbackInfo& info) { ArrayBuffer buffer = ArrayBuffer::New(info.Env(), testLength); if (buffer.ByteLength() != testLength) { - Error::New(info.Env(), "Incorrect buffer length.").ThrowAsJavaScriptException(); + Error::New(info.Env(), "Incorrect buffer length.") + .ThrowAsJavaScriptException(); return Value(); } @@ -41,12 +42,14 @@ Value CreateExternalBuffer(const CallbackInfo& info) { ArrayBuffer buffer = ArrayBuffer::New(info.Env(), testData, testLength); if (buffer.ByteLength() != testLength) { - Error::New(info.Env(), "Incorrect buffer length.").ThrowAsJavaScriptException(); + Error::New(info.Env(), "Incorrect buffer length.") + .ThrowAsJavaScriptException(); return Value(); } if (buffer.Data() != testData) { - Error::New(info.Env(), "Incorrect buffer data.").ThrowAsJavaScriptException(); + Error::New(info.Env(), "Incorrect buffer data.") + .ThrowAsJavaScriptException(); return Value(); } @@ -60,21 +63,20 @@ Value CreateExternalBufferWithFinalize(const CallbackInfo& info) { uint8_t* data = new uint8_t[testLength]; ArrayBuffer buffer = ArrayBuffer::New( - info.Env(), - data, - testLength, - [](Env /*env*/, void* finalizeData) { - delete[] static_cast(finalizeData); - finalizeCount++; - }); + info.Env(), data, testLength, [](Env /*env*/, void* finalizeData) { + delete[] static_cast(finalizeData); + finalizeCount++; + }); if (buffer.ByteLength() != testLength) { - Error::New(info.Env(), "Incorrect buffer length.").ThrowAsJavaScriptException(); + Error::New(info.Env(), "Incorrect buffer length.") + .ThrowAsJavaScriptException(); return Value(); } if (buffer.Data() != data) { - Error::New(info.Env(), "Incorrect buffer data.").ThrowAsJavaScriptException(); + Error::New(info.Env(), "Incorrect buffer data.") + .ThrowAsJavaScriptException(); return Value(); } @@ -89,22 +91,24 @@ Value CreateExternalBufferWithFinalizeHint(const CallbackInfo& info) { char* hint = nullptr; ArrayBuffer buffer = ArrayBuffer::New( - info.Env(), - data, - testLength, - [](Env /*env*/, void* finalizeData, char* /*finalizeHint*/) { - delete[] static_cast(finalizeData); - finalizeCount++; - }, - hint); + info.Env(), + data, + testLength, + [](Env /*env*/, void* finalizeData, char* /*finalizeHint*/) { + delete[] static_cast(finalizeData); + finalizeCount++; + }, + hint); if (buffer.ByteLength() != testLength) { - Error::New(info.Env(), "Incorrect buffer length.").ThrowAsJavaScriptException(); + Error::New(info.Env(), "Incorrect buffer length.") + .ThrowAsJavaScriptException(); return Value(); } if (buffer.Data() != data) { - Error::New(info.Env(), "Incorrect buffer data.").ThrowAsJavaScriptException(); + Error::New(info.Env(), "Incorrect buffer data.") + .ThrowAsJavaScriptException(); return Value(); } @@ -114,31 +118,35 @@ Value CreateExternalBufferWithFinalizeHint(const CallbackInfo& info) { void CheckBuffer(const CallbackInfo& info) { if (!info[0].IsArrayBuffer()) { - Error::New(info.Env(), "A buffer was expected.").ThrowAsJavaScriptException(); + Error::New(info.Env(), "A buffer was expected.") + .ThrowAsJavaScriptException(); return; } ArrayBuffer buffer = info[0].As(); if (buffer.ByteLength() != testLength) { - Error::New(info.Env(), "Incorrect buffer length.").ThrowAsJavaScriptException(); + Error::New(info.Env(), "Incorrect buffer length.") + .ThrowAsJavaScriptException(); return; } if (!VerifyData(static_cast(buffer.Data()), testLength)) { - Error::New(info.Env(), "Incorrect buffer data.").ThrowAsJavaScriptException(); + Error::New(info.Env(), "Incorrect buffer data.") + .ThrowAsJavaScriptException(); return; } } Value GetFinalizeCount(const CallbackInfo& info) { - return Number::New(info.Env(), finalizeCount); + return Number::New(info.Env(), finalizeCount); } Value CreateBufferWithConstructor(const CallbackInfo& info) { ArrayBuffer buffer = ArrayBuffer::New(info.Env(), testLength); if (buffer.ByteLength() != testLength) { - Error::New(info.Env(), "Incorrect buffer length.").ThrowAsJavaScriptException(); + Error::New(info.Env(), "Incorrect buffer length.") + .ThrowAsJavaScriptException(); return Value(); } InitData(static_cast(buffer.Data()), testLength); @@ -153,7 +161,8 @@ Value CheckEmptyBuffer(const CallbackInfo& info) { void CheckDetachUpdatesData(const CallbackInfo& info) { if (!info[0].IsArrayBuffer()) { - Error::New(info.Env(), "A buffer was expected.").ThrowAsJavaScriptException(); + Error::New(info.Env(), "A buffer was expected.") + .ThrowAsJavaScriptException(); return; } @@ -165,7 +174,8 @@ void CheckDetachUpdatesData(const CallbackInfo& info) { #if NAPI_VERSION >= 7 if (buffer.IsDetached()) { - Error::New(info.Env(), "Buffer should not be detached.").ThrowAsJavaScriptException(); + Error::New(info.Env(), "Buffer should not be detached.") + .ThrowAsJavaScriptException(); return; } #endif @@ -173,7 +183,8 @@ void CheckDetachUpdatesData(const CallbackInfo& info) { if (info.Length() == 2) { // Detach externally (in JavaScript). if (!info[1].IsFunction()) { - Error::New(info.Env(), "A function was expected.").ThrowAsJavaScriptException(); + Error::New(info.Env(), "A function was expected.") + .ThrowAsJavaScriptException(); return; } @@ -190,23 +201,26 @@ void CheckDetachUpdatesData(const CallbackInfo& info) { #if NAPI_VERSION >= 7 if (!buffer.IsDetached()) { - Error::New(info.Env(), "Buffer should be detached.").ThrowAsJavaScriptException(); + Error::New(info.Env(), "Buffer should be detached.") + .ThrowAsJavaScriptException(); return; } #endif if (buffer.Data() != nullptr) { - Error::New(info.Env(), "Incorrect data pointer.").ThrowAsJavaScriptException(); + Error::New(info.Env(), "Incorrect data pointer.") + .ThrowAsJavaScriptException(); return; } if (buffer.ByteLength() != 0) { - Error::New(info.Env(), "Incorrect buffer length.").ThrowAsJavaScriptException(); + Error::New(info.Env(), "Incorrect buffer length.") + .ThrowAsJavaScriptException(); return; } } -} // end anonymous namespace +} // end anonymous namespace Object InitArrayBuffer(Env env) { Object exports = Object::New(env); @@ -214,14 +228,16 @@ Object InitArrayBuffer(Env env) { exports["createBuffer"] = Function::New(env, CreateBuffer); exports["createExternalBuffer"] = Function::New(env, CreateExternalBuffer); exports["createExternalBufferWithFinalize"] = - Function::New(env, CreateExternalBufferWithFinalize); + Function::New(env, CreateExternalBufferWithFinalize); exports["createExternalBufferWithFinalizeHint"] = - Function::New(env, CreateExternalBufferWithFinalizeHint); + Function::New(env, CreateExternalBufferWithFinalizeHint); exports["checkBuffer"] = Function::New(env, CheckBuffer); exports["getFinalizeCount"] = Function::New(env, GetFinalizeCount); - exports["createBufferWithConstructor"] = Function::New(env, CreateBufferWithConstructor); + exports["createBufferWithConstructor"] = + Function::New(env, CreateBufferWithConstructor); exports["checkEmptyBuffer"] = Function::New(env, CheckEmptyBuffer); - exports["checkDetachUpdatesData"] = Function::New(env, CheckDetachUpdatesData); + exports["checkDetachUpdatesData"] = + Function::New(env, CheckDetachUpdatesData); return exports; } diff --git a/test/arraybuffer.js b/test/array_buffer.js similarity index 100% rename from test/arraybuffer.js rename to test/array_buffer.js diff --git a/test/asynccontext.cc b/test/async_context.cc similarity index 76% rename from test/asynccontext.cc rename to test/async_context.cc index bb1acbb89..ed98db938 100644 --- a/test/asynccontext.cc +++ b/test/async_context.cc @@ -8,11 +8,11 @@ static void MakeCallback(const CallbackInfo& info) { Function callback = info[0].As(); Object resource = info[1].As(); AsyncContext context(info.Env(), "async_context_test", resource); - callback.MakeCallback(Object::New(info.Env()), - std::initializer_list{}, context); + callback.MakeCallback( + Object::New(info.Env()), std::initializer_list{}, context); } -} // end anonymous namespace +} // end anonymous namespace Object InitAsyncContext(Env env) { Object exports = Object::New(env); diff --git a/test/asynccontext.js b/test/async_context.js similarity index 100% rename from test/asynccontext.js rename to test/async_context.js diff --git a/test/asyncprogressqueueworker.cc b/test/async_progress_queue_worker.cc similarity index 79% rename from test/asyncprogressqueueworker.cc rename to test/async_progress_queue_worker.cc index 23c6707ff..eec3f9510 100644 --- a/test/asyncprogressqueueworker.cc +++ b/test/async_progress_queue_worker.cc @@ -16,17 +16,14 @@ struct ProgressData { }; class TestWorker : public AsyncProgressQueueWorker { -public: + public: static Napi::Value CreateWork(const CallbackInfo& info) { int32_t times = info[0].As().Int32Value(); Function cb = info[1].As(); Function progress = info[2].As(); - TestWorker* worker = new TestWorker(cb, - progress, - "TestResource", - Object::New(info.Env()), - times); + TestWorker* worker = new TestWorker( + cb, progress, "TestResource", Object::New(info.Env()), times); return Napi::External::New(info.Env(), worker); } @@ -37,7 +34,7 @@ class TestWorker : public AsyncProgressQueueWorker { worker->Queue(); } -protected: + protected: void Execute(const ExecutionProgress& progress) override { using namespace std::chrono_literals; std::this_thread::sleep_for(1s); @@ -56,18 +53,17 @@ class TestWorker : public AsyncProgressQueueWorker { Napi::Env env = Env(); if (!_js_progress_cb.IsEmpty()) { Number progress = Number::New(env, data->progress); - _js_progress_cb.Call(Receiver().Value(), { progress }); + _js_progress_cb.Call(Receiver().Value(), {progress}); } } -private: + private: TestWorker(Function cb, Function progress, const char* resource_name, const Object& resource, int32_t times) - : AsyncProgressQueueWorker(cb, resource_name, resource), - _times(times) { + : AsyncProgressQueueWorker(cb, resource_name, resource), _times(times) { _js_progress_cb.Reset(progress, 1); } @@ -75,7 +71,7 @@ class TestWorker : public AsyncProgressQueueWorker { FunctionReference _js_progress_cb; }; -} // namespace +} // namespace Object InitAsyncProgressQueueWorker(Env env) { Object exports = Object::New(env); diff --git a/test/asyncprogressqueueworker.js b/test/async_progress_queue_worker.js similarity index 100% rename from test/asyncprogressqueueworker.js rename to test/async_progress_queue_worker.js diff --git a/test/asyncprogressworker.cc b/test/async_progress_worker.cc similarity index 90% rename from test/asyncprogressworker.cc rename to test/async_progress_worker.cc index 1705124ad..36087e7ca 100644 --- a/test/asyncprogressworker.cc +++ b/test/async_progress_worker.cc @@ -16,18 +16,19 @@ struct ProgressData { }; class TestWorker : public AsyncProgressWorker { -public: + public: static void DoWork(const CallbackInfo& info) { int32_t times = info[0].As().Int32Value(); Function cb = info[1].As(); Function progress = info[2].As(); - TestWorker* worker = new TestWorker(cb, progress, "TestResource", Object::New(info.Env())); + TestWorker* worker = + new TestWorker(cb, progress, "TestResource", Object::New(info.Env())); worker->_times = times; worker->Queue(); } -protected: + protected: void Execute(const ExecutionProgress& progress) override { if (_times < 0) { SetError("test error"); @@ -45,13 +46,16 @@ class TestWorker : public AsyncProgressWorker { Napi::Env env = Env(); if (!_progress.IsEmpty()) { Number progress = Number::New(env, data->progress); - _progress.MakeCallback(Receiver().Value(), { progress }); + _progress.MakeCallback(Receiver().Value(), {progress}); } _cv.notify_one(); } -private: - TestWorker(Function cb, Function progress, const char* resource_name, const Object& resource) + private: + TestWorker(Function cb, + Function progress, + const char* resource_name, + const Object& resource) : AsyncProgressWorker(cb, resource_name, resource) { _progress.Reset(progress, 1); } @@ -118,7 +122,7 @@ class MalignWorker : public AsyncProgressWorker { std::mutex _cvm; FunctionReference _progress; }; -} +} // namespace Object InitAsyncProgressWorker(Env env) { Object exports = Object::New(env); diff --git a/test/asyncprogressworker.js b/test/async_progress_worker.js similarity index 100% rename from test/asyncprogressworker.js rename to test/async_progress_worker.js diff --git a/test/asyncworker.cc b/test/async_worker.cc similarity index 66% rename from test/asyncworker.cc rename to test/async_worker.cc index 324146533..8efb0d5b0 100644 --- a/test/asyncworker.cc +++ b/test/async_worker.cc @@ -3,7 +3,7 @@ using namespace Napi; class TestWorker : public AsyncWorker { -public: + public: static void DoWork(const CallbackInfo& info) { bool succeed = info[0].As(); Object resource = info[1].As(); @@ -16,34 +16,35 @@ class TestWorker : public AsyncWorker { worker->Queue(); } -protected: + protected: void Execute() override { if (!_succeed) { SetError("test error"); } } -private: + private: TestWorker(Function cb, const char* resource_name, const Object& resource) : AsyncWorker(cb, resource_name, resource) {} bool _succeed; }; class TestWorkerWithResult : public AsyncWorker { -public: + public: static void DoWork(const CallbackInfo& info) { bool succeed = info[0].As(); Object resource = info[1].As(); Function cb = info[2].As(); Value data = info[3]; - TestWorkerWithResult* worker = new TestWorkerWithResult(cb, "TestResource", resource); + TestWorkerWithResult* worker = + new TestWorkerWithResult(cb, "TestResource", resource); worker->Receiver().Set("data", data); worker->_succeed = succeed; worker->Queue(); } -protected: + protected: void Execute() override { if (!_succeed) { SetError("test error"); @@ -55,40 +56,41 @@ class TestWorkerWithResult : public AsyncWorker { String::New(env, _succeed ? "ok" : "error")}; } -private: - TestWorkerWithResult(Function cb, const char* resource_name, const Object& resource) + private: + TestWorkerWithResult(Function cb, + const char* resource_name, + const Object& resource) : AsyncWorker(cb, resource_name, resource) {} bool _succeed; }; class TestWorkerNoCallback : public AsyncWorker { -public: + public: static Value DoWork(const CallbackInfo& info) { napi_env env = info.Env(); bool succeed = info[0].As(); Object resource = info[1].As(); - TestWorkerNoCallback* worker = new TestWorkerNoCallback(env, "TestResource", resource); + TestWorkerNoCallback* worker = + new TestWorkerNoCallback(env, "TestResource", resource); worker->_succeed = succeed; worker->Queue(); return worker->_deferred.Promise(); } -protected: - void Execute() override { - } - virtual void OnOK() override { - _deferred.Resolve(Env().Undefined()); - - } + protected: + void Execute() override {} + virtual void OnOK() override { _deferred.Resolve(Env().Undefined()); } virtual void OnError(const Napi::Error& /* e */) override { - _deferred.Reject(Env().Undefined()); + _deferred.Reject(Env().Undefined()); } -private: - TestWorkerNoCallback(napi_env env, const char* resource_name, const Object& resource) - : AsyncWorker(env, resource_name, resource), _deferred(Napi::Promise::Deferred::New(env)) { - } + private: + TestWorkerNoCallback(napi_env env, + const char* resource_name, + const Object& resource) + : AsyncWorker(env, resource_name, resource), + _deferred(Napi::Promise::Deferred::New(env)) {} Promise::Deferred _deferred; bool _succeed; }; @@ -96,7 +98,9 @@ class TestWorkerNoCallback : public AsyncWorker { Object InitAsyncWorker(Env env) { Object exports = Object::New(env); exports["doWork"] = Function::New(env, TestWorker::DoWork); - exports["doWorkNoCallback"] = Function::New(env, TestWorkerNoCallback::DoWork); - exports["doWorkWithResult"] = Function::New(env, TestWorkerWithResult::DoWork); + exports["doWorkNoCallback"] = + Function::New(env, TestWorkerNoCallback::DoWork); + exports["doWorkWithResult"] = + Function::New(env, TestWorkerWithResult::DoWork); return exports; } diff --git a/test/asyncworker.js b/test/async_worker.js similarity index 100% rename from test/asyncworker.js rename to test/async_worker.js diff --git a/test/asyncworker-nocallback.js b/test/async_worker_nocallback.js similarity index 100% rename from test/asyncworker-nocallback.js rename to test/async_worker_nocallback.js diff --git a/test/asyncworker-persistent.cc b/test/async_worker_persistent.cc similarity index 80% rename from test/asyncworker-persistent.cc rename to test/async_worker_persistent.cc index 97aa0cab8..90349ae34 100644 --- a/test/asyncworker-persistent.cc +++ b/test/async_worker_persistent.cc @@ -9,7 +9,7 @@ using namespace Napi; namespace { class PersistentTestWorker : public AsyncWorker { -public: + public: static PersistentTestWorker* current_worker; static void DoWork(const CallbackInfo& info) { bool succeed = info[0].As(); @@ -28,24 +28,21 @@ class PersistentTestWorker : public AsyncWorker { } static void DeleteWorker(const CallbackInfo& info) { - (void) info; + (void)info; delete current_worker; } - ~PersistentTestWorker() { - current_worker = nullptr; - } + ~PersistentTestWorker() { current_worker = nullptr; } -protected: + protected: void Execute() override { if (!_succeed) { SetError("test error"); } } -private: - PersistentTestWorker(Function cb, - const char* resource_name) + private: + PersistentTestWorker(Function cb, const char* resource_name) : AsyncWorker(cb, resource_name) {} bool _succeed; @@ -58,9 +55,8 @@ PersistentTestWorker* PersistentTestWorker::current_worker = nullptr; Object InitPersistentAsyncWorker(Env env) { Object exports = Object::New(env); exports["doWork"] = Function::New(env, PersistentTestWorker::DoWork); - exports.DefineProperty( - PropertyDescriptor::Accessor(env, exports, "workerGone", - PersistentTestWorker::GetWorkerGone)); + exports.DefineProperty(PropertyDescriptor::Accessor( + env, exports, "workerGone", PersistentTestWorker::GetWorkerGone)); exports["deleteWorker"] = Function::New(env, PersistentTestWorker::DeleteWorker); return exports; diff --git a/test/asyncworker-persistent.js b/test/async_worker_persistent.js similarity index 100% rename from test/asyncworker-persistent.js rename to test/async_worker_persistent.js diff --git a/test/binding.gyp b/test/binding.gyp index e45711af0..2969dc1f9 100644 --- a/test/binding.gyp +++ b/test/binding.gyp @@ -6,12 +6,12 @@ 'build_sources': [ 'addon.cc', 'addon_data.cc', - 'arraybuffer.cc', - 'asynccontext.cc', - 'asyncprogressqueueworker.cc', - 'asyncprogressworker.cc', - 'asyncworker.cc', - 'asyncworker-persistent.cc', + 'array_buffer.cc', + 'async_context.cc', + 'async_progress_queue_worker.cc', + 'async_progress_worker.cc', + 'async_worker.cc', + 'async_worker_persistent.cc', 'basic_types/array.cc', 'basic_types/boolean.cc', 'basic_types/number.cc', @@ -27,7 +27,7 @@ 'error.cc', 'external.cc', 'function.cc', - 'functionreference.cc', + 'function_reference.cc', 'handlescope.cc', 'maybe/check.cc', 'movable_callbacks.cc', @@ -65,9 +65,9 @@ 'typedarray.cc', 'objectwrap.cc', 'objectwrap_constructor_exception.cc', - 'objectwrap-removewrap.cc', + 'objectwrap_removewrap.cc', 'objectwrap_multiple_inheritance.cc', - 'objectreference.cc', + 'object_reference.cc', 'reference.cc', 'version_management.cc', 'thunking_manual.cc', diff --git a/test/functionreference.cc b/test/function_reference.cc similarity index 100% rename from test/functionreference.cc rename to test/function_reference.cc diff --git a/test/functionreference.js b/test/function_reference.js similarity index 100% rename from test/functionreference.js rename to test/function_reference.js diff --git a/test/objectreference.cc b/test/object_reference.cc similarity index 100% rename from test/objectreference.cc rename to test/object_reference.cc diff --git a/test/objectreference.js b/test/object_reference.js similarity index 100% rename from test/objectreference.js rename to test/object_reference.js diff --git a/test/objectwrap-removewrap.cc b/test/objectwrap_removewrap.cc similarity index 98% rename from test/objectwrap-removewrap.cc rename to test/objectwrap_removewrap.cc index fdcec07c7..a714186f0 100644 --- a/test/objectwrap-removewrap.cc +++ b/test/objectwrap_removewrap.cc @@ -1,5 +1,5 @@ -#include #include +#include namespace { @@ -18,7 +18,7 @@ Napi::Value GetDtorCalled(const Napi::CallbackInfo& info) { } class Test : public Napi::ObjectWrap { -public: + public: Test(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { #ifdef NAPI_CPP_EXCEPTIONS throw Napi::Error::New(Env(), "Some error"); @@ -32,7 +32,7 @@ class Test : public Napi::ObjectWrap { exports.Set("getDtorCalled", Napi::Function::New(env, GetDtorCalled)); } -private: + private: DtorCounter dtor_counter_; }; diff --git a/test/objectwrap-removewrap.js b/test/objectwrap_removewrap.js similarity index 100% rename from test/objectwrap-removewrap.js rename to test/objectwrap_removewrap.js