/* -*- Mode: c++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*-
**
** Copyright (C) 2003-2007 Opera Software ASA.  All rights reserved.
**
** This file is part of the Opera web browser.  It may not be distributed
** under any circumstances.
**
** Peter Karlsson
*/

group "prefs.util.upgrade";
require initialization;
require UPGRADE_SUPPORT;

include "modules/prefs/prefsmanager/prefsmanager.h";
include "modules/prefs/prefsmanager/collections/pc_network.h";
include "modules/prefs/util/upgrade.h";
include "modules/util/opfile/opmemfile.h";

// -- Tests --------------------------------------------------------------

test("Upgrading ua.ini")
	require undefined HAVE_NO_OPMEMFILE;
	require PREFS_UPGRADE_UAINI;
{
	static const unsigned char uaini[] =
		//!Opera Preferences version 2.0
		//!
		//![Identity]
		//!uaini.example.com=5
//		//!xn--l-0ga.example.com=5
//		//!www.xn--l-0ga.example.com=5
		;

	OpMemFile *ofp;
	verify((ofp = OpMemFile::Create(uaini, long(sizeof uaini))) != NULL);

	// Load the ua.ini file
	TRAPD(rc, PrefsUpgrade::UpgradeUAINIL(ofp));
	verify(OpStatus::IsSuccess(rc));

	// Check that we got the results we were looking for
	verify(5 == g_pcnet->GetIntegerPref(PrefsCollectionNetwork::UABaseId, UNI_L("uaini.example.com")));
//	verify(5 == g_pcnet->GetIntegerPref(PrefsCollectionNetwork::UABaseId, UNI_L("\366l.example.com")));
//	verify(5 == g_pcnet->GetIntegerPref(PrefsCollectionNetwork::UABaseId, UNI_L("www.\366l.example.com")));
}
finally
{
	// Clean up
#ifdef PREFS_WRITE
	g_prefsManager->RemoveOverridesL(UNI_L("uaini.example.com"), FALSE);
//	g_prefsManager->RemoveOverridesL(UNI_L("\366l.example.com"), FALSE);
//	g_prefsManager->RemoveOverridesL(UNI_L("www.\366l.example.com"), FALSE);
#endif

	OP_DELETE(ofp);
}
