文件
mynode/packages/whisper-voice-typing/cpp/utils/SingleThread_test.cpp
chen 301194963b
一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
feat: Initial clean release of CHM
2026-11-04 11:29:39 +08:00

83 行
1.8 KiB
C++

#include "SingleThread_test.hpp"
#include "SingleThread.hpp"
#include "testing.hpp"
#include "androidUtil.h"
#include <string>
#include <vector>
#include <sstream>
#include <cmath>
#include <random>
void shouldConstructAndDestruct();
void shouldReturnSingleValue();
void shouldReturnMultipleAsync();
void shouldForwardExceptions();
void SingleThread_test() {
LOGD("SingleThread: Starting tests...");
shouldConstructAndDestruct();
shouldReturnSingleValue();
shouldReturnMultipleAsync();
shouldForwardExceptions();
}
void shouldConstructAndDestruct() {
{
SingleThread thread {};
LOGD("SingleThread: Constructed!");
}
LOGD("SingleThread: Destructed!");
logTestPass("shouldConstructAndDestruct");
}
void shouldReturnSingleValue() {
SingleThread thread {};
LOGD("SingleThread: Posting a value and waiting!");
assertEqual(thread.runAndWait<int>([] {
LOGD("SingleThread: Inside thread!");
return 3;
}), 3, "should support returning a value from a lambda");
LOGD("SingleThread: Posted a value and waited!");
logTestPass("shouldReturnSingleValue");
}
void shouldReturnMultipleAsync() {
SingleThread thread {};
auto future1 = thread.run<int>([] {
return 1;
});
auto future2 = thread.run<int>([] {
return 2;
});
auto future3 = thread.run<int>([] {
return 3;
});
assertEqual(future1.get(), 1, "getting future1");
assertEqual(future3.get(), 3, "getting future3");
assertEqual(future2.get(), 2, "getting future2");
logTestPass("shouldReturnMultipleAsync");
}
void shouldForwardExceptions() {
SingleThread thread {};
bool caught = false;
try {
thread.runAndWait<void>([] {
throw std::runtime_error("testing...");
});
} catch (std::runtime_error ex) {
caught = true;
}
assertEqual(caught, true, "should have caught the exception");
logTestPass("shouldForwardExceptions");
}