|
1 // Copyright (c) 1994-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 the License "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 // e32test\system\t_cli.cpp |
|
15 // Overview: |
|
16 // Command line tests |
|
17 // API Information: |
|
18 // User::CommandLine, User::CommandLineLength |
|
19 // Details: |
|
20 // - Test the command line data and the command line length. |
|
21 // Verify the results are as expected. |
|
22 // Platforms/Drives/Compatibility: |
|
23 // All. |
|
24 // Assumptions/Requirement/Pre-requisites: |
|
25 // Failures and causes: |
|
26 // Base Port information: |
|
27 // |
|
28 // |
|
29 |
|
30 #include <e32std.h> |
|
31 #include <e32std_private.h> |
|
32 #include <e32test.h> |
|
33 #include <e32panic.h> |
|
34 |
|
35 _LIT(KLitKernExec,"KERN-EXEC"); |
|
36 _LIT(KCmdLine, "Turnip goat fridge, far larder mungo humm. Yes?"); |
|
37 |
|
38 const TInt EExitError = -1; |
|
39 const TInt EExitCmdLineMatch = 42; |
|
40 const TInt EExitCmdLine256 = 43; |
|
41 |
|
42 LOCAL_D RTest test(_L("T_CLI")); |
|
43 |
|
44 void runtests() |
|
45 { |
|
46 |
|
47 test.Next(_L("Test short commmand line")); |
|
48 TRequestStatus stat; |
|
49 RProcess p; |
|
50 TBuf<280> text=KCmdLine(); |
|
51 TFileName filename; |
|
52 filename=p.FileName(); |
|
53 TInt r=p.Create(filename,text); |
|
54 test(r==KErrNone); |
|
55 test.Next(_L("Run and close process")); |
|
56 p.Logon(stat); |
|
57 p.Resume(); |
|
58 User::WaitForRequest(stat); |
|
59 test(p.ExitType()==EExitKill); |
|
60 test(p.ExitReason()==EExitCmdLineMatch); |
|
61 CLOSE_AND_WAIT(p); |
|
62 |
|
63 test.Next(_L("Test command line with length 256")); |
|
64 text.SetLength(256); |
|
65 text.Fill('Z'); |
|
66 test.Next(_L("Create process")); |
|
67 r=p.Create(filename, text); |
|
68 test(r==KErrNone); |
|
69 test.Next(_L("Run and close process")); |
|
70 p.Logon(stat); |
|
71 p.Resume(); |
|
72 User::WaitForRequest(stat); |
|
73 test(p.ExitType()==EExitKill); |
|
74 test(p.ExitReason()==EExitCmdLine256); |
|
75 CLOSE_AND_WAIT(p); |
|
76 |
|
77 test.Next(_L("Test long command line")); |
|
78 text.SetLength(280); |
|
79 text.Fill('a'); |
|
80 r=p.Create(filename, text); |
|
81 test(r==KErrNone); |
|
82 test.Next(_L("Run and close process")); |
|
83 p.Logon(stat); |
|
84 p.SetJustInTime(EFalse); // don't let debugger spoil the test |
|
85 p.Resume(); |
|
86 User::WaitForRequest(stat); |
|
87 test.Next(_L("Test Panic type")); |
|
88 test.Printf(_L("%d %d\n"), p.ExitType(), p.ExitReason()); |
|
89 test(p.ExitType()==EExitPanic); |
|
90 test(p.ExitReason()==EKUDesSetLengthOverflow); |
|
91 test(p.ExitCategory()==KLitKernExec); |
|
92 CLOSE_AND_WAIT(p); |
|
93 } |
|
94 |
|
95 GLDEF_C TInt E32Main() |
|
96 { |
|
97 |
|
98 test.Title(); |
|
99 test.Start(_L("Command line")); |
|
100 |
|
101 TInt r; |
|
102 TInt len=User::CommandLineLength(); |
|
103 TBuf<256> c; |
|
104 if (len==0) |
|
105 { |
|
106 runtests(); |
|
107 r = 0; |
|
108 } |
|
109 else if (len == KCmdLine().Length()) |
|
110 { |
|
111 User::CommandLine(c); |
|
112 r = (c.Match(KCmdLine) == 0) ? EExitCmdLineMatch : EExitError; |
|
113 } |
|
114 else |
|
115 { |
|
116 test.Next(_L("Test CommandLine(void)")); |
|
117 // This should panic for command lines > 256 |
|
118 User::CommandLine(c); |
|
119 r = EExitCmdLine256; |
|
120 } |
|
121 |
|
122 test.End(); |
|
123 return r; |
|
124 } |