sysstatemgmt/systemstatemgr/test/tsus/src/tsus_step_supinfo.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @test
       
    19  @internalComponent - Internal Symbian test code 
       
    20 */
       
    21 
       
    22 #include <s32mem.h>
       
    23 #include <ssm/ssmsuscli.h>
       
    24 
       
    25 #include "tsus_step_supinfo.h"
       
    26 
       
    27 
       
    28 //
       
    29 // TestStep
       
    30 //
       
    31 
       
    32 
       
    33 _LIT(KFileName, "abcdefgh.txt");
       
    34 const TUid KId = {12345};
       
    35 const TInt KOrdinal = 27;
       
    36 
       
    37 CSsmSupInfoTest::~CSsmSupInfoTest()
       
    38 	{
       
    39 	}
       
    40 
       
    41 CSsmSupInfoTest::CSsmSupInfoTest()
       
    42 	{
       
    43 	SetTestStepName(KTSsmSupInfoStep);
       
    44 	}
       
    45 
       
    46 /** */
       
    47 TVerdict CSsmSupInfoTest::doTestStepPreambleL()
       
    48 	{
       
    49 	return CTestStep::doTestStepPreambleL();
       
    50 	}
       
    51 
       
    52 /** 
       
    53  Old Test CaseID 		APPFWK-SUS-0001
       
    54  New Test CaseID 		DEVSRVS-SSMA-SUS-0001
       
    55  */
       
    56 
       
    57 TVerdict CSsmSupInfoTest::doTestStepL()
       
    58 	{
       
    59 	doTestStructL();
       
    60 	doTestSerializationL();
       
    61 	return TestStepResult();
       
    62 	}
       
    63 
       
    64 /** */
       
    65 TVerdict CSsmSupInfoTest::doTestStepPostambleL()
       
    66 	{
       
    67 	return CTestStep::doTestStepPostambleL();
       
    68 	}
       
    69 
       
    70 /** */
       
    71 void CSsmSupInfoTest::doTestStructL()
       
    72 	{
       
    73 	INFO_PRINTF1(_L("Testing all public methods except Internalize/Externalize"));
       
    74 	TSsmSupInfo empty;
       
    75 	TEST(empty.FileName() == KNullDesC);
       
    76 	TEST(empty.Identity() == KNullUid);
       
    77 	TEST(empty.NewLOrdinal() == 1);
       
    78 	
       
    79 	TSsmSupInfo nameOnly(KFileName);
       
    80 	TEST(nameOnly.FileName() == KFileName);
       
    81 	TEST(nameOnly.Identity() == KNullUid);
       
    82 	TEST(nameOnly.NewLOrdinal() == 1);
       
    83 	
       
    84 	TSsmSupInfo nameAndId(KFileName, KOrdinal);
       
    85 	TEST(nameAndId.FileName() == KFileName);
       
    86 	TEST(nameAndId.Identity() == KNullUid);
       
    87 	TEST(nameAndId.NewLOrdinal() == KOrdinal);
       
    88 	
       
    89 	TSsmSupInfo all(KFileName, KOrdinal, KId);
       
    90 	TEST(all.FileName() == KFileName);
       
    91 	TEST(all.Identity() == KId);
       
    92 	TEST(all.NewLOrdinal() == KOrdinal);
       
    93 	
       
    94 	empty.SetL(KFileName, KOrdinal, KId);
       
    95 	TEST(empty.FileName() == KFileName);
       
    96 	TEST(empty.Identity() == KId);
       
    97 	TEST(empty.NewLOrdinal() == KOrdinal);
       
    98 	}
       
    99 
       
   100 /** */
       
   101 void CSsmSupInfoTest::doTestSerializationL()
       
   102 	{
       
   103 	INFO_PRINTF1(_L("Testing Internalize/Externalize"));
       
   104 	
       
   105 	// Create a supinfo with non default values
       
   106 	TSsmSupInfo supinfo;
       
   107 	supinfo.SetL(KFileName, KOrdinal, KId);
       
   108 	
       
   109 	// Externalize it
       
   110 	CBufFlat* buf = CBufFlat::NewL( 1024 );
       
   111 	CleanupStack::PushL( buf );	
       
   112 	RBufWriteStream writeStream( *buf );
       
   113 	CleanupClosePushL( writeStream );	
       
   114 	supinfo.ExternalizeL( writeStream );
       
   115 	CleanupStack::PopAndDestroy( &writeStream );
       
   116 	
       
   117 	// Create a new startupprop instance 
       
   118 	TSsmSupInfo second_supinfo;
       
   119 	
       
   120 	// Internalize the data
       
   121 	RBufReadStream readStream( *buf );
       
   122 	CleanupClosePushL( readStream );	
       
   123 	second_supinfo.InternalizeL( readStream );
       
   124 	CleanupStack::PopAndDestroy( &readStream );
       
   125 	
       
   126 	// And TEST that all members was read back successfully
       
   127 	TEST(supinfo.FileName() == second_supinfo.FileName());
       
   128 	TEST(supinfo.Identity() == second_supinfo.Identity());
       
   129 	TEST(supinfo.NewLOrdinal() == second_supinfo.NewLOrdinal());
       
   130 	
       
   131 	// Externalize the second instance
       
   132 	CBufFlat* buf2 = CBufFlat::NewL( 1024 );
       
   133 	CleanupStack::PushL( buf2 );	
       
   134 	RBufWriteStream writeStream2( *buf2 );
       
   135 	CleanupClosePushL( writeStream2 );	
       
   136 	second_supinfo.ExternalizeL( writeStream2 );
       
   137 	CleanupStack::PopAndDestroy( &writeStream2 );
       
   138 	
       
   139 	// Assert that the first and second buffer have the same contents
       
   140 	TEST(buf->Ptr(0) == buf2->Ptr(0));
       
   141 	
       
   142 	CleanupStack::PopAndDestroy( buf2 );
       
   143 	CleanupStack::PopAndDestroy( buf );
       
   144 	}