Squashed 'deps/nostalgia/' content from commit 9cb6bd4a
git-subtree-dir: deps/nostalgia git-subtree-split: 9cb6bd4a32e9f39a858f72443ff5c6d40489fe22
This commit is contained in:
18
deps/nfde/test/CMakeLists.txt
vendored
Normal file
18
deps/nfde/test/CMakeLists.txt
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
|
||||
set(TEST_LIST
|
||||
test_opendialog.c
|
||||
test_opendialog_cpp.cpp
|
||||
test_opendialogmultiple.c
|
||||
test_opendialogmultiple_cpp.cpp
|
||||
test_opendialogmultiple_enum.c
|
||||
test_pickfolder.c
|
||||
test_pickfolder_cpp.cpp
|
||||
test_savedialog.c)
|
||||
|
||||
foreach (TEST ${TEST_LIST})
|
||||
string(REPLACE "." "_" CLEAN_TEST_NAME ${TEST})
|
||||
add_executable(${CLEAN_TEST_NAME}
|
||||
${TEST})
|
||||
target_link_libraries(${CLEAN_TEST_NAME}
|
||||
PUBLIC nfd)
|
||||
endforeach()
|
36
deps/nfde/test/test_opendialog.c
vendored
Normal file
36
deps/nfde/test/test_opendialog.c
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
#include <nfd.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/* this test should compile on all supported platforms */
|
||||
|
||||
int main(void) {
|
||||
// initialize NFD
|
||||
// either call NFD_Init at the start of your program and NFD_Quit at the end of your program,
|
||||
// or before/after every time you want to show a file dialog.
|
||||
NFD_Init();
|
||||
|
||||
nfdchar_t* outPath;
|
||||
|
||||
// prepare filters for the dialog
|
||||
nfdfilteritem_t filterItem[2] = {{"Source code", "c,cpp,cc"}, {"Headers", "h,hpp"}};
|
||||
|
||||
// show the dialog
|
||||
nfdresult_t result = NFD_OpenDialog(&outPath, filterItem, 2, NULL);
|
||||
if (result == NFD_OKAY) {
|
||||
puts("Success!");
|
||||
puts(outPath);
|
||||
// remember to free the memory (since NFD_OKAY is returned)
|
||||
NFD_FreePath(outPath);
|
||||
} else if (result == NFD_CANCEL) {
|
||||
puts("User pressed cancel.");
|
||||
} else {
|
||||
printf("Error: %s\n", NFD_GetError());
|
||||
}
|
||||
|
||||
// Quit NFD
|
||||
NFD_Quit();
|
||||
|
||||
return 0;
|
||||
}
|
29
deps/nfde/test/test_opendialog_cpp.cpp
vendored
Normal file
29
deps/nfde/test/test_opendialog_cpp.cpp
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
#include <iostream>
|
||||
#include "nfd.hpp"
|
||||
|
||||
/* this test should compile on all supported platforms */
|
||||
/* this demonstrates the thin C++ wrapper */
|
||||
|
||||
int main() {
|
||||
// initialize NFD
|
||||
NFD::Guard nfdGuard;
|
||||
|
||||
// auto-freeing memory
|
||||
NFD::UniquePath outPath;
|
||||
|
||||
// prepare filters for the dialog
|
||||
nfdfilteritem_t filterItem[2] = {{"Source code", "c,cpp,cc"}, {"Headers", "h,hpp"}};
|
||||
|
||||
// show the dialog
|
||||
nfdresult_t result = NFD::OpenDialog(outPath, filterItem, 2);
|
||||
if (result == NFD_OKAY) {
|
||||
std::cout << "Success!" << std::endl << outPath.get() << std::endl;
|
||||
} else if (result == NFD_CANCEL) {
|
||||
std::cout << "User pressed cancel." << std::endl;
|
||||
} else {
|
||||
std::cout << "Error: " << NFD::GetError() << std::endl;
|
||||
}
|
||||
|
||||
// NFD::Guard will automatically quit NFD.
|
||||
return 0;
|
||||
}
|
50
deps/nfde/test/test_opendialogmultiple.c
vendored
Normal file
50
deps/nfde/test/test_opendialogmultiple.c
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
#include <nfd.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/* this test should compile on all supported platforms */
|
||||
|
||||
int main(void) {
|
||||
// initialize NFD
|
||||
// either call NFD_Init at the start of your program and NFD_Quit at the end of your program,
|
||||
// or before/after every time you want to show a file dialog.
|
||||
NFD_Init();
|
||||
|
||||
const nfdpathset_t* outPaths;
|
||||
|
||||
// prepare filters for the dialog
|
||||
nfdfilteritem_t filterItem[2] = {{"Source code", "c,cpp,cc"}, {"Headers", "h,hpp"}};
|
||||
|
||||
// show the dialog
|
||||
nfdresult_t result = NFD_OpenDialogMultiple(&outPaths, filterItem, 2, NULL);
|
||||
|
||||
if (result == NFD_OKAY) {
|
||||
puts("Success!");
|
||||
|
||||
nfdpathsetsize_t numPaths;
|
||||
NFD_PathSet_GetCount(outPaths, &numPaths);
|
||||
|
||||
nfdpathsetsize_t i;
|
||||
for (i = 0; i < numPaths; ++i) {
|
||||
nfdchar_t* path;
|
||||
NFD_PathSet_GetPath(outPaths, i, &path);
|
||||
printf("Path %i: %s\n", (int)i, path);
|
||||
|
||||
// remember to free the pathset path with NFD_PathSet_FreePath (not NFD_FreePath!)
|
||||
NFD_PathSet_FreePath(path);
|
||||
}
|
||||
|
||||
// remember to free the pathset memory (since NFD_OKAY is returned)
|
||||
NFD_PathSet_Free(outPaths);
|
||||
} else if (result == NFD_CANCEL) {
|
||||
puts("User pressed cancel.");
|
||||
} else {
|
||||
printf("Error: %s\n", NFD_GetError());
|
||||
}
|
||||
|
||||
// Quit NFD
|
||||
NFD_Quit();
|
||||
|
||||
return 0;
|
||||
}
|
40
deps/nfde/test/test_opendialogmultiple_cpp.cpp
vendored
Normal file
40
deps/nfde/test/test_opendialogmultiple_cpp.cpp
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
#include "nfd.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
/* this test should compile on all supported platforms */
|
||||
/* this demonstrates the thin C++ wrapper */
|
||||
|
||||
int main() {
|
||||
// initialize NFD
|
||||
NFD::Guard nfdGuard;
|
||||
|
||||
// auto-freeing memory
|
||||
NFD::UniquePathSet outPaths;
|
||||
|
||||
// prepare filters for the dialog
|
||||
nfdfilteritem_t filterItem[2] = {{"Source code", "c,cpp,cc"}, {"Headers", "h,hpp"}};
|
||||
|
||||
// show the dialog
|
||||
nfdresult_t result = NFD::OpenDialogMultiple(outPaths, filterItem, 2);
|
||||
if (result == NFD_OKAY) {
|
||||
std::cout << "Success!" << std::endl;
|
||||
|
||||
nfdpathsetsize_t numPaths;
|
||||
NFD::PathSet::Count(outPaths, numPaths);
|
||||
|
||||
nfdpathsetsize_t i;
|
||||
for (i = 0; i < numPaths; ++i) {
|
||||
NFD::UniquePathSetPath path;
|
||||
NFD::PathSet::GetPath(outPaths, i, path);
|
||||
std::cout << "Path " << i << ": " << path.get() << std::endl;
|
||||
}
|
||||
} else if (result == NFD_CANCEL) {
|
||||
std::cout << "User pressed cancel." << std::endl;
|
||||
} else {
|
||||
std::cout << "Error: " << NFD::GetError() << std::endl;
|
||||
}
|
||||
|
||||
// NFD::Guard will automatically quit NFD.
|
||||
return 0;
|
||||
}
|
53
deps/nfde/test/test_opendialogmultiple_enum.c
vendored
Normal file
53
deps/nfde/test/test_opendialogmultiple_enum.c
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
#include <nfd.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/* this test should compile on all supported platforms */
|
||||
|
||||
int main(void) {
|
||||
// initialize NFD
|
||||
// either call NFD_Init at the start of your program and NFD_Quit at the end of your program,
|
||||
// or before/after every time you want to show a file dialog.
|
||||
NFD_Init();
|
||||
|
||||
const nfdpathset_t* outPaths;
|
||||
|
||||
// prepare filters for the dialog
|
||||
nfdfilteritem_t filterItem[2] = {{"Source code", "c,cpp,cc"}, {"Headers", "h,hpp"}};
|
||||
|
||||
// show the dialog
|
||||
nfdresult_t result = NFD_OpenDialogMultiple(&outPaths, filterItem, 2, NULL);
|
||||
|
||||
if (result == NFD_OKAY) {
|
||||
puts("Success!");
|
||||
|
||||
// declare enumerator (not a pointer)
|
||||
nfdpathsetenum_t enumerator;
|
||||
|
||||
NFD_PathSet_GetEnum(outPaths, &enumerator);
|
||||
nfdchar_t* path;
|
||||
unsigned i = 0;
|
||||
while (NFD_PathSet_EnumNext(&enumerator, &path) && path) {
|
||||
printf("Path %u: %s\n", i++, path);
|
||||
|
||||
// remember to free the pathset path with NFD_PathSet_FreePath (not NFD_FreePath!)
|
||||
NFD_PathSet_FreePath(path);
|
||||
}
|
||||
|
||||
// remember to free the pathset enumerator memory (before freeing the pathset)
|
||||
NFD_PathSet_FreeEnum(&enumerator);
|
||||
|
||||
// remember to free the pathset memory (since NFD_OKAY is returned)
|
||||
NFD_PathSet_Free(outPaths);
|
||||
} else if (result == NFD_CANCEL) {
|
||||
puts("User pressed cancel.");
|
||||
} else {
|
||||
printf("Error: %s\n", NFD_GetError());
|
||||
}
|
||||
|
||||
// Quit NFD
|
||||
NFD_Quit();
|
||||
|
||||
return 0;
|
||||
}
|
33
deps/nfde/test/test_pickfolder.c
vendored
Normal file
33
deps/nfde/test/test_pickfolder.c
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
#include <nfd.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/* this test should compile on all supported platforms */
|
||||
|
||||
int main(void) {
|
||||
// initialize NFD
|
||||
// either call NFD_Init at the start of your program and NFD_Quit at the end of your program,
|
||||
// or before/after every time you want to show a file dialog.
|
||||
NFD_Init();
|
||||
|
||||
nfdchar_t* outPath;
|
||||
|
||||
// show the dialog
|
||||
nfdresult_t result = NFD_PickFolder(&outPath, NULL);
|
||||
if (result == NFD_OKAY) {
|
||||
puts("Success!");
|
||||
puts(outPath);
|
||||
// remember to free the memory (since NFD_OKAY is returned)
|
||||
NFD_FreePath(outPath);
|
||||
} else if (result == NFD_CANCEL) {
|
||||
puts("User pressed cancel.");
|
||||
} else {
|
||||
printf("Error: %s\n", NFD_GetError());
|
||||
}
|
||||
|
||||
// Quit NFD
|
||||
NFD_Quit();
|
||||
|
||||
return 0;
|
||||
}
|
27
deps/nfde/test/test_pickfolder_cpp.cpp
vendored
Normal file
27
deps/nfde/test/test_pickfolder_cpp.cpp
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
#include "nfd.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
/* this test should compile on all supported platforms */
|
||||
/* this demonstrates the thin C++ wrapper */
|
||||
|
||||
int main() {
|
||||
// initialize NFD
|
||||
NFD::Guard nfdGuard;
|
||||
|
||||
// auto-freeing memory
|
||||
NFD::UniquePath outPath;
|
||||
|
||||
// show the dialog
|
||||
nfdresult_t result = NFD::PickFolder(outPath);
|
||||
if (result == NFD_OKAY) {
|
||||
std::cout << "Success!" << std::endl << outPath.get() << std::endl;
|
||||
} else if (result == NFD_CANCEL) {
|
||||
std::cout << "User pressed cancel." << std::endl;
|
||||
} else {
|
||||
std::cout << "Error: " << NFD::GetError() << std::endl;
|
||||
}
|
||||
|
||||
// NFD::Guard will automatically quit NFD.
|
||||
return 0;
|
||||
}
|
36
deps/nfde/test/test_savedialog.c
vendored
Normal file
36
deps/nfde/test/test_savedialog.c
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
#include <nfd.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/* this test should compile on all supported platforms */
|
||||
|
||||
int main(void) {
|
||||
// initialize NFD
|
||||
// either call NFD_Init at the start of your program and NFD_Quit at the end of your program,
|
||||
// or before/after every time you want to show a file dialog.
|
||||
NFD_Init();
|
||||
|
||||
nfdchar_t* savePath;
|
||||
|
||||
// prepare filters for the dialog
|
||||
nfdfilteritem_t filterItem[2] = {{"Source code", "c,cpp,cc"}, {"Header", "h,hpp"}};
|
||||
|
||||
// show the dialog
|
||||
nfdresult_t result = NFD_SaveDialog(&savePath, filterItem, 2, NULL, "Untitled.c");
|
||||
if (result == NFD_OKAY) {
|
||||
puts("Success!");
|
||||
puts(savePath);
|
||||
// remember to free the memory (since NFD_OKAY is returned)
|
||||
NFD_FreePath(savePath);
|
||||
} else if (result == NFD_CANCEL) {
|
||||
puts("User pressed cancel.");
|
||||
} else {
|
||||
printf("Error: %s\n", NFD_GetError());
|
||||
}
|
||||
|
||||
// Quit NFD
|
||||
NFD_Quit();
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user