forked from btzy/nativefiledialog-extended
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test: Add tests with NFD_NATIVE (btzy#122)
- Loading branch information
Showing
6 changed files
with
274 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#define NFD_NATIVE | ||
#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 | ||
#ifdef _WIN32 | ||
nfdfilteritem_t filterItem[2] = {{L"Source code", L"c,cpp,cc"}, {L"Headers", L"h,hpp"}}; | ||
#else | ||
nfdfilteritem_t filterItem[2] = {{"Source code", "c,cpp,cc"}, {"Headers", "h,hpp"}}; | ||
#endif | ||
|
||
// show the dialog | ||
nfdresult_t result = NFD_OpenDialog(&outPath, filterItem, 2, NULL); | ||
if (result == NFD_OKAY) { | ||
puts("Success!"); | ||
#ifdef _WIN32 | ||
#ifdef _MSC_VER | ||
_putws(outPath); | ||
#else | ||
fputws(outPath, stdin); | ||
#endif | ||
#else | ||
puts(outPath); | ||
#endif | ||
// 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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#define NFD_NATIVE | ||
#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 | ||
#ifdef _WIN32 | ||
nfdfilteritem_t filterItem[2] = {{L"Source code", L"c,cpp,cc"}, {L"Headers", L"h,hpp"}}; | ||
#else | ||
nfdfilteritem_t filterItem[2] = {{"Source code", "c,cpp,cc"}, {"Headers", "h,hpp"}}; | ||
#endif | ||
|
||
// 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) { | ||
#ifdef _WIN32 | ||
wprintf(L"Path %u: %s\n", i++, path); | ||
#else | ||
printf("Path %u: %s\n", i++, path); | ||
#endif | ||
|
||
// 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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#define NFD_NATIVE | ||
#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 | ||
#ifdef _WIN32 | ||
nfdfilteritem_t filterItem[2] = {{L"Source code", L"c,cpp,cc"}, {L"Headers", L"h,hpp"}}; | ||
#else | ||
nfdfilteritem_t filterItem[2] = {{"Source code", "c,cpp,cc"}, {"Headers", "h,hpp"}}; | ||
#endif | ||
|
||
// 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); | ||
#ifdef _WIN32 | ||
wprintf(L"Path %i: %s\n", (int)i, path); | ||
#else | ||
printf("Path %i: %s\n", (int)i, path); | ||
#endif | ||
|
||
// 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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#define NFD_NATIVE | ||
#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!"); | ||
#ifdef _WIN32 | ||
#ifdef _MSC_VER | ||
_putws(outPath); | ||
#else | ||
fputws(outPath, stdin); | ||
#endif | ||
#else | ||
puts(outPath); | ||
#endif | ||
// 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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#define NFD_NATIVE | ||
#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 | ||
#ifdef _WIN32 | ||
nfdfilteritem_t filterItem[2] = {{L"Source code", L"c,cpp,cc"}, {L"Headers", L"h,hpp"}}; | ||
#else | ||
nfdfilteritem_t filterItem[2] = {{"Source code", "c,cpp,cc"}, {"Headers", "h,hpp"}}; | ||
#endif | ||
|
||
#ifdef _WIN32 | ||
const wchar_t* defaultPath = L"Untitled.c"; | ||
#else | ||
const char* defaultPath = "Untitled.c"; | ||
#endif | ||
|
||
// show the dialog | ||
nfdresult_t result = NFD_SaveDialog(&savePath, filterItem, 2, NULL, defaultPath); | ||
if (result == NFD_OKAY) { | ||
puts("Success!"); | ||
#ifdef _WIN32 | ||
#ifdef _MSC_VER | ||
_putws(savePath); | ||
#else | ||
fputws(savePath, stdin); | ||
#endif | ||
#else | ||
puts(savePath); | ||
#endif | ||
// 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; | ||
} |