Click here to Skip to main content
5,788,212 members and growing! (17,319 online)
Email Password   helpLost your password?
General Programming » Algorithms & Recipes » General     Intermediate License: The Code Project Open License (CPOL)

Generate Meta-Strings for Testing Your Application

By MarkLTX

A utility for generating self-describing strings that are useful for testing an application's string handling abilities.
C# 2.0, C#, Windows, .NET, .NET 2.0VS2005, Visual Studio, Dev, QA

Posted: 8 Sep 2007
Updated: 8 Aug 2008
Views: 7,532
Bookmarked: 16 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
10 votes for this Article.
Popularity: 4.56 Rating: 4.56 out of 5
0 votes, 0.0%
1
0 votes, 0.0%
2
1 vote, 10.0%
3
1 vote, 10.0%
4
8 votes, 80.0%
5

Introduction

A meta-string describes its own length and internal offsets. Meta-strings are useful for testing an application's ability to accept and process arbitrarily long strings without truncating them because you can tell at a glance if and where a meta-string has been truncated.

For example, suppose an application is required to handle up to 10,000 characters in a certain text box of a Properties dialog. You can easily generate a 10,000 char meta-string, paste it in, and tell at a glance if it "fits" or if it gets truncated after being saved and reloaded.

Definition of a Meta-String

A meta-string is basically a list of numbers such that each number is equal to its position in the string. The numbers in the string are separated by the character of your choice, such as a dash. Meta-strings come in two flavors; decreasing and increasing. The following increasing and decreasing meta-strings are both 60 chars long:

1-3-5-7-9-12-15-18-21-24-27-30-33-36-39-42-45-48-51-54-57-60
60-57-54-51-48-45-42-39-36-33-30-27-24-21-18-15-12-9-7-5-3-1

Properties of Increasing Meta-Strings

The numbers in an increasing meta-string tell you the length (or position) of the string at the end of each number. Therefore, an increasing string always ends with the string's total length. However, they don't always start with '1'. Sometimes they start with "-2" as in the following example. It is difficult to predict which case will occur for a given length without actually generating the string.

-2-4-6-8-11

An increasing meta-string makes it easy to tell what the new length of a string is after being truncated on the right. For example, you can tell the following string was truncated and the new length is 29. Just start with the last intact number (27) and count two more chars to the end. Unfortunately, you can't tell just by looking what the original length was. Also, if the string gets truncated at the "wrong" length (e.g. 27), you can't tell if it was truncated at all unless you know the original length.

1-3-5-7-9-12-15-18-21-24-27-3

Properties of Decreasing Meta-Strings

The numbers in a decreasing meta-string tell you the number of chars remaining in the string from the beginning of each number (i.e. including the number itself). Therefore, a decreasing string always starts with the string's total length. They always end with '1' or "2-".

If a decreasing string doesn't end with '1' or "2-", you know it has been truncated on the right. You can tell the original length by looking at the beginning of the string. You can tell how many characters were lost by looking at the end and compute the new length by subtraction.

For example, you can tell the following string originally had 255 chars. You can tell 211 chars were lost, by finding the last intact number (215) and subtracting the number of chars from that point to the end (4). Thus, the length of this string is 255 - 211 = 44.

255-251-247-243-239-235-231-227-223-219-215-

Meta-String Generator

The code that accompanies this article is a small GUI utility that generates meta-strings and puts them on the clipboard so you can paste them into other applications. The internal code has no explicit limit on the length, but the Length text box only accepts seven characters so the maximum length is 9999999 (i.e., 10,000,000 - 1). That should be enough for most applications.

It only takes a few seconds to generate a max length (9999999) string. However, it takes a very long time to paste it into Notepad for some reason. At least, Notepad will accept the entire string. Notepad++ truncates at 65,564. It also misbehaves if you try to position the cursor past 65,536. Maybe the Notepad++ developers should have done some testing with meta-strings.

History

  • 8th September, 2007: Initial post
  • 6th August, 2008: Article updated

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

MarkLTX


Mark Lauritsen has been a software developer for as long as he can remember.
Occupation: Software Developer (Senior)
Location: United States United States

Other popular Algorithms & Recipes articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 7 of 7 (Total in Forum: 7) (Refresh)FirstPrevNext
QuestionAny chance the compiled code can be posted here?memberbillgall19:06 5 Aug '08  
AnswerRe: Any chance the compiled code can be posted here?memberMarkLTX7:41 6 Aug '08  
AnswerRe: Any chance the compiled code can be posted here?memberMarkLTX17:59 8 Aug '08  
GeneralRe: Any chance the compiled code can be posted here?memberbillgall18:52 8 Aug '08  
GeneralGood ideamemberJakub Mller2:48 10 Sep '07  
GeneralRe: Good ideamemberleppie12:34 16 Sep '07  
GeneralWell there's an ideamemberreinux21:52 8 Sep '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 8 Aug 2008
Editor: Deeksha Shenoy
Copyright 2007 by MarkLTX
Everything else Copyright © CodeProject, 1999-2009
Web18 | Advertise on the Code Project