Skip to content

Commit

Permalink
Merge pull request #1103 from nokotan/v6_develop_add_tests
Browse files Browse the repository at this point in the history
テストコードの追加
  • Loading branch information
Reputeless authored Nov 13, 2023
2 parents c665c52 + 4cca724 commit ad3d66a
Show file tree
Hide file tree
Showing 81 changed files with 3,706 additions and 2,151 deletions.
22 changes: 17 additions & 5 deletions .github/workflows/ci_web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ jobs:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[skip ci]') && !contains(github.event.head_commit.message, '[ci skip]')"

container:
image: emscripten/emsdk:3.1.20

steps:
- uses: actions/checkout@v3

- name: Setup emsdk
uses: mymindstorm/setup-emsdk@v11
with:
version: 3.1.20
actions-cache-folder: 'emsdk'

- name: Install Boost
uses: ./.github/actions/download-boost
with:
Expand All @@ -40,7 +43,15 @@ jobs:
- name: Build Siv3D
working-directory: Web
run: |
cmake --build build
cmake --build build --parallel 4
- name: Run Siv3DTest
working-directory: Web/build
run: |
export DISPLAY=:1
Xvfb -ac ${DISPLAY} -screen 0 1280x1024x24 > /dev/null 2>&1 &
emrun --browser chrome --timeout 600 --timeout_returncode -1 Siv3DTest.html
emrun --browser chrome --timeout 600 --timeout_returncode -1 Siv3DUnitTest.html
- name: Install Siv3D
working-directory: Web
Expand All @@ -61,5 +72,6 @@ jobs:
- name: Run Siv3DApp
working-directory: Web/App
run: |
export DISPLAY=:1
cd build
emrun.py --timeout 180 --timeout_returncode 0 Siv3DApp.html
emrun --browser chrome --timeout 180 --timeout_returncode 0 Siv3DApp.html
10 changes: 0 additions & 10 deletions Siv3D/include/Siv3D/EngineLog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,6 @@
# define LOG_VERBOSE(S) s3d::Internal::OutputEngineLog(s3d::LogType::Verbose, S)
# define LOG_SCOPED_TRACE(S) const s3d::Internal::ScopedEngineLog s3d_scoped_trace{s3d::LogType::Trace, S}

# elif SIV3D_PLATFORM(WEB)

# define LOG_ERROR(S) s3d::Internal::OutputEngineLog(s3d::LogType::Error, S)
# define LOG_FAIL(S) s3d::Internal::OutputEngineLog(s3d::LogType::Fail, S)
# define LOG_WARNING(S) s3d::Internal::OutputEngineLog(s3d::LogType::Warning, S)
# define LOG_INFO(S) ((void)0)
# define LOG_TRACE(S) ((void)0)
# define LOG_VERBOSE(S) ((void)0)
# define LOG_SCOPED_TRACE(S) ((void)0)

# else

# define LOG_ERROR(S) s3d::Internal::OutputEngineLog(s3d::LogType::Error, S)
Expand Down
4 changes: 4 additions & 0 deletions Siv3D/include/Siv3D/detail/AsyncTask.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ namespace s3d
template <class Type>
template <class Fty, class... Args, std::enable_if_t<std::is_invocable_v<Fty, Args...>>*>
inline AsyncTask<Type>::AsyncTask(Fty&& f, Args&&... args)
# if !SIV3D_PLATFORM(WEB) || defined(__EMSCRIPTEN_PTHREADS__)
: m_data{ std::async(std::launch::async, std::forward<Fty>(f), std::forward<Args>(args)...) } {}
# else
: m_data{} {}
# endif

template <class Type>
inline AsyncTask<Type>& AsyncTask<Type>::operator =(base_type&& other) noexcept
Expand Down
42 changes: 42 additions & 0 deletions Siv3D/lib/Web/jslib/Siv3D.AudioDecode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
mergeInto(LibraryManager.library, {
siv3dDecodeAudioFromFileAsync: function(filePath, callback, arg) {
const path = UTF8ToString(filePath, 1024);
const fileBytes = FS.readFile(path);

const onSuccess = function(decoded) {
const leftDataBuffer = Module["_malloc"](decoded.length * 4);
HEAPF32.set(decoded.getChannelData(0), leftDataBuffer>>2);

let rightDataBuffer;

if (decoded.numberOfChannels >= 2) {
rightDataBuffer = Module["_malloc"](decoded.length * 4);
HEAPF32.set(decoded.getChannelData(1), rightDataBuffer>>2);
} else {
rightDataBuffer = leftDataBuffer;
}

HEAP32[(arg>>2)+0] = leftDataBuffer;
HEAP32[(arg>>2)+1] = rightDataBuffer;
HEAPU32[(arg>>2)+2] = decoded.sampleRate;
HEAPU32[(arg>>2)+3] = decoded.length;

{{{ makeDynCall('vi', 'callback') }}}(arg);
_siv3dMaybeAwake();
};

const onFailure = function() {
HEAP32[(arg>>2)+0] = 0;
HEAP32[(arg>>2)+1] = 0;
HEAPU32[(arg>>2)+2] = 0;
HEAPU32[(arg>>2)+3] = 0;

{{{ makeDynCall('vi', 'callback') }}}(arg);
_siv3dMaybeAwake();
}

Module["SDL2"].audioContext.decodeAudioData(fileBytes.buffer, onSuccess, onFailure);
},
siv3dDecodeAudioFromFileAsync__sig: "viii",
siv3dDecodeAudioFromFileAsync__deps: [ "$AL", "$FS", "siv3dMaybeAwake" ],
});
75 changes: 75 additions & 0 deletions Siv3D/lib/Web/jslib/Siv3D.Clipboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
mergeInto(LibraryManager.library, {
siv3dSetClipboardText: function(ctext) {
const text = UTF8ToString(ctext);

siv3dRegisterUserAction(function () {
navigator.clipboard.writeText(text);
});
},
siv3dSetClipboardText__sig: "vi",
siv3dSetClipboardText__proxy: "sync",
siv3dSetClipboardText__deps: [ "$siv3dRegisterUserAction" ],

$siv3dGetClipboardTextImpl: function(wakeUp) {
if (!navigator.clipboard.readText) {
err("Reading clipboard is not allowed in this browser.");
wakeUp(0);
return;
}

siv3dRegisterUserAction(function () {
navigator.clipboard.readText()
.then(function(str) {
const strPtr = allocate(intArrayFromString(str), ALLOC_NORMAL);
wakeUp(strPtr);
})
.catch(function(_) {
wakeUp(0);
});
});
},
$siv3dGetClipboardTextImpl__deps: [ "$siv3dRegisterUserAction" ],

#if ASYNCIFY
siv3dGetClipboardText: function() {
return Asyncify.handleSleep(siv3dGetClipboardTextImpl);
},
siv3dGetClipboardText__sig: "iv",
siv3dGetClipboardText__deps: [ "$siv3dGetClipboardTextImpl", "$Asyncify" ],
#elif PROXY_TO_PTHREAD
siv3dGetClipboardText: function(ctx) {
siv3dGetClipboardTextImpl(function () {
Module["_emscripten_proxy_finish"](ctx);
});
},
siv3dGetClipboardText__sig: "ii",
siv3dGetClipboardText__deps: [ "$siv3dGetClipboardTextImpl" ],
#else
siv3dGetClipboardText: function() {
return 0;
},
siv3dGetClipboardText__sig: "iv",
#endif

siv3dGetClipboardTextAsync: function(callback, promise) {
siv3dRegisterUserAction(function () {
if (!navigator.clipboard.readText) {
err("Reading clipboard is not allowed in this browser.");
{{{ makeDynCall('vii', 'callback') }}}(0, promise);
return;
}

navigator.clipboard.readText()
.then(function(str) {
const strPtr = allocate(intArrayFromString(str), ALLOC_NORMAL);
{{{ makeDynCall('vii', 'callback') }}}(strPtr, promise);
Module["_free"](strPtr);
})
.catch(function (e) {
{{{ makeDynCall('vii', 'callback') }}}(0, promise);
});
});
},
siv3dGetClipboardTextAsync__sig: "vii",
siv3dGetClipboardTextAsync__deps: [ "$siv3dRegisterUserAction" ],
});
110 changes: 110 additions & 0 deletions Siv3D/lib/Web/jslib/Siv3D.Dialog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
mergeInto(LibraryManager.library, {
$siv3dInputElement: null,
$siv3dDialogFileReader: null,
$siv3dDownloadLink: null,

siv3dInitDialog: function() {
siv3dInputElement = document.createElement("input");
siv3dInputElement.type = "file";

siv3dDialogFileReader = new FileReader();
siv3dDownloadLink = document.createElement("a");
},
siv3dInitDialog__sig: "v",
siv3dInitDialog__deps: [ "$siv3dInputElement", "$siv3dDialogFileReader", "$siv3dDownloadLink" ],

$siv3dOpenDialogAsync: function(filter, callback, futurePtr, acceptMuilitple) {
siv3dInputElement.accept = filter;
siv3dInputElement.multiple = acceptMuilitple;

function cancelHandler(e) {
{{{ makeDynCall('viii', 'callback') }}}(0, 0, futurePtr);
_siv3dMaybeAwake();
}

// Using addEventListener works in Firefox
// Set 'once' to automatically delete the handler when the event fires
siv3dInputElement.addEventListener('cancel', cancelHandler, { once: true });

siv3dInputElement.oninput = async function(e) {
// Delete event handler if cancel event is not fired
siv3dInputElement.removeEventListener('cancel', cancelHandler);

// Workaround for event firing
const files = [...e.target.files];
e.target.value = '';

if (files.length < 1) {
callback(0, 0, futurePtr);
_siv3dMaybeAwake();
return;
}

let filePathes = [];
const sp = stackSave();

for (let file of files) {
await new Promise((resolve) => {
const filePath = "/tmp/" + file.name;

siv3dDialogFileReader.addEventListener("load", function onLoaded() {
FS.writeFile(filePath, new Uint8Array(siv3dDialogFileReader.result));

const namePtr = allocate(intArrayFromString(filePath), ALLOC_STACK);
filePathes.push(namePtr);

siv3dDialogFileReader.removeEventListener("load", onLoaded);
resolve();
});

siv3dDialogFileReader.readAsArrayBuffer(file);
});
}

const filePathesPtr = stackAlloc(filePathes.length * {{{ POINTER_SIZE }}});

for (let i = 0; i < filePathes.length; i++) {
setValue(filePathesPtr + i * {{{ POINTER_SIZE }}}, filePathes[i], "i32");
}

callback(filePathesPtr, filePathes.length, futurePtr);

stackRestore(sp);
_siv3dMaybeAwake();
};

siv3dRegisterUserAction(function() {
siv3dInputElement.click();
});
},
$siv3dOpenDialogAsync__deps: [ "$siv3dInputElement", "$siv3dDialogFileReader", "$siv3dRegisterUserAction", "$FS", "siv3dMaybeAwake" ],
siv3dOpenDialogAsync: function(filterStr, callback, futurePtr, acceptMuilitple) {
const filter = UTF8ToString(filterStr);
const callbackFn = {{{ makeDynCall('viii', 'callback') }}};
siv3dOpenDialogAsync(filter, callbackFn, futurePtr, !!acceptMuilitple);
},
siv3dOpenDialogAsync__sig: "vii",
siv3dOpenDialogAsync__deps: [ "$siv3dOpenDialogAsync" ],

$siv3dSaveFileBuffer: null,
$siv3dSaveFileBufferWritePos: 0,
$siv3dDefaultSaveFileName: null,

siv3dDownloadFile: function(filePathPtr, fileNamePtr, mimeTypePtr) {
const filePath = UTF8ToString(filePathPtr);
const fileName = UTF8ToString(fileNamePtr);
const mimeType = mimeTypePtr ? UTF8ToString(mimeTypePtr) : "application/octet-stream";
const fileData = FS.readFile(filePath);

const blob = new Blob([ fileData ], { type: mimeType });

siv3dDownloadLink.href = URL.createObjectURL(blob);
siv3dDownloadLink.download = fileName;

siv3dRegisterUserAction(function() {
siv3dDownloadLink.click();
});
},
siv3dDownloadFile__sig: "viii",
siv3dDownloadFile__deps: [ "$siv3dRegisterUserAction" ],
});
90 changes: 90 additions & 0 deletions Siv3D/lib/Web/jslib/Siv3D.DragDrop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
mergeInto(LibraryManager.library, {
$siv3dRegisterDragEnter: function(callback) {
Module["canvas"]["ondragenter"] = function (e) {
e.preventDefault();

const types = e.dataTransfer.types;

if (types.length > 0) {
const adusted = siv3dAdjustPoint(e.pageX, e.pageY);
callback(types[0] === 'Files' ? 1 : 0, adusted.x, adusted.y);
}
};
},
siv3dRegisterDragEnter: function(ptr) {
siv3dRegisterDragEnter({{{ makeDynCall('viii', 'ptr') }}});
},
siv3dRegisterDragEnter__deps: [ "$siv3dRegisterDragEnter" ],
siv3dRegisterDragEnter__sig: "vi",

$siv3dRegisterDragUpdate: function(callback) {
Module["canvas"]["ondragover"] = function (e) {
e.preventDefault();
const adusted = siv3dAdjustPoint(e.pageX, e.pageY);
callback(adusted.x, adusted.y);
};
},
siv3dRegisterDragUpdate: function(ptr) {
siv3dRegisterDragUpdate({{{ makeDynCall('vii', 'ptr') }}});
},
siv3dRegisterDragUpdate__sig: "vi",
siv3dRegisterDragUpdate__deps: [ "$siv3dRegisterDragUpdate", "$siv3dAdjustPoint" ],

$siv3dRegisterDragExit: function(callback) {
Module["canvas"]["ondragexit"] = function (e) {
e.preventDefault();
callback();
};
},
siv3dRegisterDragExit: function(ptr) {
siv3dRegisterDragExit({{{ makeDynCall('v', 'ptr') }}});
},
siv3dRegisterDragExit__deps: [ "$siv3dRegisterDragExit" ],
siv3dRegisterDragExit__sig: "vi",

$siv3dDragDropFileReader: null,
$siv3dRegisterDragDrop: function(callback) {
Module["canvas"]["ondrop"] = function (e) {
e.preventDefault();

const items = e.dataTransfer.items;
const adusted = siv3dAdjustPoint(e.pageX, e.pageY);

if (items.length == 0) {
return;
}

if (items[0].kind === 'string') {
items[0].getAsString(function(str) {
const strPtr = allocate(intArrayFromString(str), ALLOC_NORMAL);
callback(strPtr, adusted.x, adusted.y);
Module["_free"](strPtr);
})
} else if (items[0].kind === 'file') {
const file = items[0].getAsFile();

if (!siv3dDragDropFileReader) {
siv3dDragDropFileReader = new FileReader();
}

const filePath = "/tmp/" + file.name;

siv3dDragDropFileReader.addEventListener("load", function onLoaded() {
FS.writeFile(filePath, new Uint8Array(siv3dDragDropFileReader.result));

const namePtr = allocate(intArrayFromString(filePath), ALLOC_NORMAL);
callback(namePtr, adusted.x, adusted.y);

siv3dDragDropFileReader.removeEventListener("load", onLoaded);
});

siv3dDragDropFileReader.readAsArrayBuffer(file);
}
};
},
siv3dRegisterDragDrop: function(ptr) {
siv3dRegisterDragDrop({{{ makeDynCall('viii', 'ptr') }}});
},
siv3dRegisterDragDrop__sig: "vi",
siv3dRegisterDragDrop__deps: [ "$siv3dRegisterDragDrop", "$siv3dDragDropFileReader", "$FS" ],
});
Loading

0 comments on commit ad3d66a

Please sign in to comment.