Squashed 'deps/nfde/' content from commit 28ade5a5c
git-subtree-dir: deps/nfde git-subtree-split: 28ade5a5cc5d17cea8fe4034572cac8fd54eb53f
This commit is contained in:
		
							
								
								
									
										18
									
								
								test/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								test/CMakeLists.txt
									
									
									
									
									
										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
									
								
								test/test_opendialog.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								test/test_opendialog.c
									
									
									
									
									
										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
									
								
								test/test_opendialog_cpp.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								test/test_opendialog_cpp.cpp
									
									
									
									
									
										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
									
								
								test/test_opendialogmultiple.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								test/test_opendialogmultiple.c
									
									
									
									
									
										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
									
								
								test/test_opendialogmultiple_cpp.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								test/test_opendialogmultiple_cpp.cpp
									
									
									
									
									
										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
									
								
								test/test_opendialogmultiple_enum.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								test/test_opendialogmultiple_enum.c
									
									
									
									
									
										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
									
								
								test/test_pickfolder.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								test/test_pickfolder.c
									
									
									
									
									
										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
									
								
								test/test_pickfolder_cpp.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								test/test_pickfolder_cpp.cpp
									
									
									
									
									
										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
									
								
								test/test_savedialog.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								test/test_savedialog.c
									
									
									
									
									
										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