omap3530/omap3530_drivers/spi/test/t_spi_client_m.cpp
branchBeagle_BSP_dev
changeset 77 e5fd00cbb70a
child 82 65b40f262685
equal deleted inserted replaced
76:29b14275133a 77:e5fd00cbb70a
       
     1 // This component and the accompanying materials are made available
       
     2 // under the terms of the License "Eclipse Public License v1.0"
       
     3 // which accompanies this distribution, and is available
       
     4 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     5 //
       
     6 // Initial Contributors:
       
     7 // lukasz.forynski@gmail.com
       
     8 //
       
     9 // Contributors:
       
    10 //
       
    11 //
       
    12 // Description:
       
    13 // omap3530_drivers/spi/test/t_spi_client_master.cpp
       
    14 //
       
    15 // user-side application for the simple SPI client (master) test driver.
       
    16 //
       
    17 
       
    18 #include <e32test.h>
       
    19 #include <e32cmn.h>
       
    20 #include "d_spi_client_m.h"
       
    21 
       
    22 
       
    23 // global data..
       
    24 _LIT(testName,"T_SPI_CLIENT_M");
       
    25 GLDEF_D RTest test(testName);
       
    26 
       
    27 GLDEF_D RSpiClientTest testLdd; // the actual driver..
       
    28 
       
    29 void PrepareDriver()
       
    30 	{
       
    31 	// Load the Test Driver
       
    32 	TInt r = User::LoadLogicalDevice(KLddFileName);
       
    33 	if(r != KErrNone && r != KErrAlreadyExists)
       
    34 		{
       
    35 		// fail..
       
    36 		test.Printf(_L("\nFailed to load the driver, r=%d"), r);
       
    37 		test(EFalse);
       
    38 		}
       
    39 
       
    40 	// Open the driver
       
    41 	r = testLdd.Open();
       
    42 	if(r != KErrNone)
       
    43 		{
       
    44 		test.Printf(_L("Failed to open the driver..\n\r"));
       
    45 		test(EFalse);
       
    46 		}
       
    47 	}
       
    48 
       
    49 void ReleaseDriver()
       
    50 	{
       
    51 	// Close the driver
       
    52 	testLdd.Close();
       
    53 
       
    54 	// unload the driver
       
    55 	User::FreeLogicalDevice(KLddFileName);
       
    56 	}
       
    57 
       
    58 inline void TestError(TInt r)
       
    59 	{
       
    60 	if(r == KErrNotSupported) // this is to warn stuf not yet implemented (TDD)
       
    61 		{
       
    62 		test.Printf(_L("!! Warning: not implemented yet..\n\r"));
       
    63 		}
       
    64 	else
       
    65 		{
       
    66 		test(r == KErrNone);
       
    67 		}
       
    68 	}
       
    69 
       
    70 void TestSynchronousOperation()
       
    71 	{
       
    72 	test.Next(_L("TestSynchronousOperation()"));
       
    73 
       
    74 	test.Next(_L("HalfDuplexSingleWrite()"));
       
    75 	TestError(testLdd.HalfDuplexSingleWrite());
       
    76 
       
    77 	test.Next(_L("HalfDuplexMultipleWrite()"));
       
    78 	TestError(testLdd.HalfDuplexMultipleWrite());
       
    79 
       
    80 	test.Next(_L("HalfDuplexSingleRead()"));
       
    81 	TestError(testLdd.HalfDuplexSingleRead());
       
    82 
       
    83 	test.Next(_L("HalfDuplexMultipleRead()"));
       
    84 	TestError(testLdd.HalfDuplexMultipleRead());
       
    85 
       
    86 	test.Next(_L("HalfDuplexMultipleWriteRead()"));
       
    87 	TestError(testLdd.HalfDuplexMultipleWriteRead());
       
    88 
       
    89 	test.Next(_L("FullDuplexSingle()"));
       
    90 	TestError(testLdd.FullDuplexSingle());
       
    91 
       
    92 	test.Next(_L("FullDuplexMultiple()"));
       
    93 	TestError(testLdd.FullDuplexMultiple());
       
    94 	}
       
    95 
       
    96 
       
    97 TInt E32Main()
       
    98 	{
       
    99 	test.Title();
       
   100 	test.Start(_L("Testing SPI.."));
       
   101 
       
   102 	PrepareDriver();
       
   103 
       
   104 	TestSynchronousOperation();
       
   105 
       
   106 	ReleaseDriver();
       
   107 
       
   108 	test.End();
       
   109 
       
   110 	return KErrNone;
       
   111 	}
       
   112