2002-05-08 10:08:25 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-19 02:01:16 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2002-05-08 10:08:25 +04:00
|
|
|
*
|
2004-04-19 02:01:16 +04:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
2002-05-08 10:08:25 +04:00
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-19 02:01:16 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2002-05-08 10:08:25 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-19 02:01:16 +04:00
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
2002-05-08 10:08:25 +04:00
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-19 02:01:16 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2002-05-08 10:08:25 +04:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-19 02:01:16 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2002-05-08 10:08:25 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
2004-10-22 00:57:17 +04:00
|
|
|
#include "TestCommon.h"
|
2002-05-08 10:08:25 +04:00
|
|
|
#include "nsXPCOM.h"
|
2005-11-08 22:23:00 +03:00
|
|
|
#include "nsStringAPI.h"
|
2002-05-08 10:08:25 +04:00
|
|
|
#include "nsIPersistentProperties2.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIComponentRegistrar.h"
|
|
|
|
#include "nsIURL.h"
|
|
|
|
#include "nsIIOService.h"
|
|
|
|
#include "nsNetCID.h"
|
|
|
|
#include "nsIChannel.h"
|
|
|
|
#include "nsIComponentManager.h"
|
|
|
|
#include "nsIEnumerator.h"
|
2004-02-07 05:41:10 +03:00
|
|
|
#include <stdio.h>
|
2005-11-08 22:23:00 +03:00
|
|
|
#include "nsComponentManagerUtils.h"
|
|
|
|
#include "nsServiceManagerUtils.h"
|
2002-05-08 10:08:25 +04:00
|
|
|
|
|
|
|
#define TEST_URL "resource:/res/test.properties"
|
2002-08-30 21:13:34 +04:00
|
|
|
static NS_DEFINE_CID(kPersistentPropertiesCID, NS_IPERSISTENTPROPERTIES_CID);
|
2002-05-08 10:08:25 +04:00
|
|
|
|
|
|
|
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char* argv[])
|
|
|
|
{
|
2004-10-22 00:57:17 +04:00
|
|
|
if (test_common_init(&argc, &argv) != 0)
|
|
|
|
return -1;
|
|
|
|
|
2002-05-08 10:08:25 +04:00
|
|
|
nsresult ret;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIServiceManager> servMan;
|
|
|
|
NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull);
|
|
|
|
nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servMan);
|
|
|
|
NS_ASSERTION(registrar, "Null nsIComponentRegistrar");
|
|
|
|
registrar->AutoRegister(nsnull);
|
|
|
|
|
|
|
|
nsIInputStream* in = nsnull;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIIOService> service(do_GetService(kIOServiceCID, &ret));
|
|
|
|
if (NS_FAILED(ret)) return ret;
|
|
|
|
|
|
|
|
nsIChannel *channel = nsnull;
|
|
|
|
ret = service->NewChannel(NS_LITERAL_CSTRING(TEST_URL), nsnull, nsnull, &channel);
|
|
|
|
if (NS_FAILED(ret)) return ret;
|
|
|
|
|
|
|
|
ret = channel->Open(&in);
|
|
|
|
if (NS_FAILED(ret)) return ret;
|
|
|
|
|
2004-11-01 21:50:36 +03:00
|
|
|
nsIPersistentProperties* props;
|
|
|
|
ret = CallCreateInstance(kPersistentPropertiesCID, &props);
|
2002-05-08 10:08:25 +04:00
|
|
|
if (NS_FAILED(ret) || (!props)) {
|
|
|
|
printf("create nsIPersistentProperties failed\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
ret = props->Load(in);
|
|
|
|
if (NS_FAILED(ret)) {
|
|
|
|
printf("cannot load properties\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
int i = 1;
|
|
|
|
while (1) {
|
|
|
|
char name[16];
|
|
|
|
name[0] = 0;
|
|
|
|
sprintf(name, "%d", i);
|
|
|
|
nsAutoString v;
|
2002-08-30 21:13:34 +04:00
|
|
|
ret = props->GetStringProperty(nsDependentCString(name), v);
|
2002-05-08 10:08:25 +04:00
|
|
|
if (NS_FAILED(ret) || (!v.Length())) {
|
|
|
|
break;
|
|
|
|
}
|
2005-11-08 22:23:00 +03:00
|
|
|
printf("\"%d\"=\"%s\"\n", i, NS_ConvertUTF16toUTF8(v).get());
|
2002-05-08 10:08:25 +04:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2002-08-30 21:13:34 +04:00
|
|
|
nsCOMPtr<nsISimpleEnumerator> propEnum;
|
|
|
|
ret = props->Enumerate(getter_AddRefs(propEnum));
|
|
|
|
|
2002-05-08 10:08:25 +04:00
|
|
|
if (NS_FAILED(ret)) {
|
2002-08-30 21:13:34 +04:00
|
|
|
printf("cannot enumerate properties\n");
|
|
|
|
return 1;
|
2002-05-08 10:08:25 +04:00
|
|
|
}
|
2002-08-30 21:13:34 +04:00
|
|
|
|
2002-05-08 10:08:25 +04:00
|
|
|
|
2004-02-07 05:41:10 +03:00
|
|
|
printf("\nKey\tValue\n");
|
|
|
|
printf( "---\t-----\n");
|
2002-08-30 21:13:34 +04:00
|
|
|
|
|
|
|
PRBool hasMore;
|
|
|
|
while (NS_SUCCEEDED(propEnum->HasMoreElements(&hasMore)) &&
|
|
|
|
hasMore) {
|
|
|
|
nsCOMPtr<nsISupports> sup;
|
|
|
|
ret = propEnum->GetNext(getter_AddRefs(sup));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPropertyElement> propElem = do_QueryInterface(sup, &ret);
|
2002-05-08 10:08:25 +04:00
|
|
|
if (NS_FAILED(ret)) {
|
2002-08-30 21:13:34 +04:00
|
|
|
printf("failed to get current item\n");
|
|
|
|
return 1;
|
2002-05-08 10:08:25 +04:00
|
|
|
}
|
|
|
|
|
2002-08-30 21:13:34 +04:00
|
|
|
nsCAutoString key;
|
|
|
|
nsAutoString value;
|
2002-05-08 10:08:25 +04:00
|
|
|
|
2002-08-30 21:13:34 +04:00
|
|
|
ret = propElem->GetKey(key);
|
2002-05-08 10:08:25 +04:00
|
|
|
if (NS_FAILED(ret)) {
|
|
|
|
printf("failed to get current element's key\n");
|
|
|
|
return 1;
|
|
|
|
}
|
2002-08-30 21:13:34 +04:00
|
|
|
ret = propElem->GetValue(value);
|
2002-05-08 10:08:25 +04:00
|
|
|
if (NS_FAILED(ret)) {
|
|
|
|
printf("failed to get current element's value\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2004-10-27 05:05:09 +04:00
|
|
|
printf("%s\t%s\n", key.get(), NS_ConvertUTF16toUTF8(value).get());
|
2002-05-08 10:08:25 +04:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|