1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/xpcom/tests/TestINIParser.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,61 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#include <string.h> 1.9 + 1.10 +#include "nsXPCOM.h" 1.11 +#include "nsINIParser.h" 1.12 +#include "nsIFile.h" 1.13 + 1.14 +static bool 1.15 +StringCB(const char *aKey, const char *aValue, void* aClosure) 1.16 +{ 1.17 + printf("%s=%s\n", aKey, aValue); 1.18 + 1.19 + return true; 1.20 +} 1.21 + 1.22 +static bool 1.23 +SectionCB(const char *aSection, void* aClosure) 1.24 +{ 1.25 + nsINIParser *ini = reinterpret_cast<nsINIParser*>(aClosure); 1.26 + 1.27 + printf("[%s]\n", aSection); 1.28 + 1.29 + ini->GetStrings(aSection, StringCB, nullptr); 1.30 + 1.31 + printf("\n"); 1.32 + 1.33 + return true; 1.34 +} 1.35 + 1.36 +int main(int argc, char **argv) 1.37 +{ 1.38 + if (argc < 2) { 1.39 + fprintf(stderr, "Usage: %s <ini-file>\n", argv[0]); 1.40 + return 255; 1.41 + } 1.42 + 1.43 + nsCOMPtr<nsIFile> lf; 1.44 + 1.45 + nsresult rv = NS_NewNativeLocalFile(nsDependentCString(argv[1]), 1.46 + true, 1.47 + getter_AddRefs(lf)); 1.48 + if (NS_FAILED(rv)) { 1.49 + fprintf(stderr, "Error: NS_NewNativeLocalFile failed\n"); 1.50 + return 1; 1.51 + } 1.52 + 1.53 + nsINIParser ini; 1.54 + rv = ini.Init(lf); 1.55 + if (NS_FAILED(rv)) { 1.56 + fprintf(stderr, "Error: Init failed."); 1.57 + return 2; 1.58 + } 1.59 + 1.60 + ini.GetSections(SectionCB, &ini); 1.61 + 1.62 + return 0; 1.63 +} 1.64 +