Author: fmantek
Date: Mon Mar 26 06:42:21 2007
New Revision: 121
Modified:
trunk/clients/cs/RELEASE_NOTES.txt
trunk/clients/cs/src/core/utilities.cs
trunk/clients/cs/src/unittests/authtest.cs
trunk/clients/cs/src/unittests/coretest.cs
trunk/clients/cs/src/unittests/unittests.cs
Log:
fixed captcha message parsing
Modified: trunk/clients/cs/RELEASE_NOTES.txt
==============================================================================
--- trunk/clients/cs/RELEASE_NOTES.txt (original)
+++ trunk/clients/cs/RELEASE_NOTES.txt Mon Mar 26 06:42:21 2007
@@ -11,6 +11,8 @@
- added Captcha Handling and more detailed exceptions when the authentication
request fails. See authexceptions.cs for the list of potential exceptions
thrown
- added some preliminary unittests for the new exceptions
+- added a new constructor for the TokenCollection, so that captcha parsing is
handled correctly
+- made the debug output depending on the TRACE define, and removed that define
for the release build
== 1.0.9.4 ==
- Google Base: fix for incorrect Price attribute behaviour
Modified: trunk/clients/cs/src/core/utilities.cs
==============================================================================
--- trunk/clients/cs/src/core/utilities.cs (original)
+++ trunk/clients/cs/src/core/utilities.cs Mon Mar 26 06:42:21 2007
@@ -420,7 +420,7 @@
readStream.Close();
Tracing.TraceMsg("got the following body back: " + body);
// all we are interested is the token, so we break the string in
parts
- TokenCollection tokens = new TokenCollection(body, new char[2]
{'=', '\n'});
+ TokenCollection tokens = new TokenCollection(body, new char[1]
{'='}, true, 2);
return tokens;
}
/////////////////////////////////////////////////////////////////////////////
@@ -465,7 +465,7 @@
public class TokenCollection : IEnumerable
{
private string[] elements;
-
+
/// <summary>Constructor, takes a string and a delimiter set</summary>
public TokenCollection(string source, char[] delimiters)
{
@@ -476,6 +476,35 @@
}
}
+ /// <summary>Constructor, takes a string and a delimiter
set</summary>
+ public TokenCollection(string source, char[] delimiters,
+ bool seperateLines, int resultsPerLine)
+ {
+ if (source != null)
+ {
+ if (seperateLines == true)
+ {
+ // first split the source into a line array
+ string [] lines = source.Split(new char[] {'\n'});
+ int size = lines.Length * resultsPerLine;
+ this.elements = new string[size];
+ size = 0;
+ foreach (String s in lines)
+ {
+ string []temp = s.Split(delimiters, resultsPerLine);
+ foreach (String r in temp )
+ {
+ this.elements[size++] = r;
+ }
+ }
+ }
+ else
+ {
+ this.elements = source.Split(delimiters, resultsPerLine);
+ }
+ }
+ }
+
/// <summary>IEnumerable Interface Implementation, for the
noninterface</summary>
public TokenEnumerator GetEnumerator() // non-IEnumerable version
{
@@ -539,6 +568,5 @@
}
}
/////////////////////////////////////////////////////////////////////////////
-
}
/////////////////////////////////////////////////////////////////////////////
Modified: trunk/clients/cs/src/unittests/authtest.cs
==============================================================================
--- trunk/clients/cs/src/unittests/authtest.cs (original)
+++ trunk/clients/cs/src/unittests/authtest.cs Mon Mar 26 06:42:21 2007
@@ -159,8 +159,6 @@
FeedQuery query = new FeedQuery();
Service service = new Service();
- int iCount;
-
if (this.defaultUri != null)
{
if (this.userName != null)
@@ -198,8 +196,6 @@
FeedQuery query = new FeedQuery();
Service service = new Service();
- int iCount;
-
if (this.defaultUri != null)
{
if (this.userName != null)
@@ -221,11 +217,52 @@
{
Tracing.TraceMsg("Got the correct Exception");
}
- service.Credentials = null;
+ catch (CaptchaRequiredException e)
+ {
+ Console.WriteLine("Token: {0}", e.Token);
+ Console.WriteLine("URL: {0}", e.Url);
+ Tracing.TraceMsg("Got the correct Exception");
+ }
+ service.Credentials = null;
factory.MethodOverride = false;
}
}
////////////////////////////////////////////////////////////////////////////
+
+
+ //////////////////////////////////////////////////////////////////////
+ /// <summary>catpcha test
+ /// </summary>
+ //////////////////////////////////////////////////////////////////////
+ [Test]
+ [Ignore("don't want to block the account all the time")]
+ public void CaptchaTest()
+ {
+
+ Uri uri = new
Uri("http://www.google.com/calendar/feeds/default/private/full");
+
+ CalendarService service = new CalendarService("foo");
+ service.setUserCredentials(this.userName, "foobar");
+
+ for (int i = 0; i < 50; i++)
+ {
+ try
+ {
+ service.Query(uri);
+ }
+ catch (InvalidCredentialsException)
+ {
+ // keep going
+ }
+ catch (CaptchaRequiredException e)
+ {
+ Console.WriteLine("Token: {0}", e.Token);
+ Console.WriteLine("URL: {0}", e.Url);
+
+ break;
+ }
+ }
+ }
}
/////////////////////////////////////////////////////////////////////////////
}
Modified: trunk/clients/cs/src/unittests/coretest.cs
==============================================================================
--- trunk/clients/cs/src/unittests/coretest.cs (original)
+++ trunk/clients/cs/src/unittests/coretest.cs Mon Mar 26 06:42:21 2007
@@ -446,6 +446,50 @@
}
/////////////////////////////////////////////////////////////////////////////
+ //////////////////////////////////////////////////////////////////////
+ /// <summary>tests the tokenizer collection</summary>
+ //////////////////////////////////////////////////////////////////////
+ [Test] public void TestTokenCollection()
+ {
+ Tracing.TraceMsg("Entering TestTokenCollection");
+ String toTest =
"Test=Test?other=whatever\nTest2=Line2?other=whatishere";
+
+ TokenCollection tokens = new TokenCollection(toTest, new char[]
{'\n', '='});
+ TokenCollection tokenSmart = new TokenCollection(toTest, new
char[] {'='}, true, 2);
+
+ int iTokens = 0;
+ foreach (string token in tokens)
+ {
+ // tokens should have 5 tokens, as the = signs split into 5
+ iTokens++;
+ if (iTokens == 1)
+ {
+ Assert.IsTrue(token.Equals("Test"), "The first token
should be Test, but it is: " + token);
+ }
+ if (iTokens == 4)
+ {
+ Assert.IsTrue(token.Equals("Test2"), "The fourth token
should be Test2 but it is: " + token);
+ }
+ }
+
+ iTokens = 0;
+ foreach (string token in tokenSmart)
+ {
+ // tokens should have 5 tokens, as the = signs split into 5
+ iTokens++;
+ if (iTokens == 1)
+ {
+ Assert.IsTrue(token.Equals("Test"), "The first smart token
should be Test, but it is: " + token);
+ }
+ if (iTokens == 4)
+ {
+ Assert.IsTrue(token.Equals("Line2?other=whatishere"), "The
fourth smart token should be whatishere, but it is: " + token);
+ }
+ }
+
+
+
+ }
} /// end of CoreTestSuite
}
Modified: trunk/clients/cs/src/unittests/unittests.cs
==============================================================================
--- trunk/clients/cs/src/unittests/unittests.cs (original)
+++ trunk/clients/cs/src/unittests/unittests.cs Mon Mar 26 06:42:21 2007
@@ -338,10 +338,11 @@
Tracing.TraceMsg("Entering TestIt");
// CalendarTestSuite test = new CalendarTestSuite();
- BloggerTestSuite test = new BloggerTestSuite();
+ // BloggerTestSuite test = new BloggerTestSuite();
+ CoreTestSuite test = new CoreTestSuite();
test.InitTest();
- test.BloggerHTMLTest();
+ test.TestTokenCollection();
test.EndTest();
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Data API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/google-help-dataapi?hl=en
-~----------~----~----~----~------~----~------~--~---