Dynamic tests with mstest and T4

(0 rating, 0 votes)

Mar 5th, 2011

If you used mstest and NUnit you might be aware of the fact that the former doesn’t support dynamic, data driven test cases. For example, the following scenario cannot be achieved with the out-of-box mstest: given a dataset, create distinct test cases for each entry in it, using a predefined generic test case.

The best result that can be achieved using mstest is a single testcase that will iterate through the dataset. There is one disadvantage: if the test fails for one entry in the dataset, the whole test case fails.

So, in order to overcome the previously mentioned limitation, I decided to create a text template that will generate the test cases for me. As an example, I will write some tests for an integer multiplication function that has 2 bugs in it:

public int Multiply(int a, int b)
{
    //This conditions are simulating the 2 bugs
    if (a == 0 && b == 1)
        return 100;
    if (a == 1 && b == 0)
        return -100;
    return a * b;
}

The classical approach (no dynamic test)

Without using any ‘hacks’, one could write the tests for the Multiply function in the following way:

//Tuple description <value of param a, value of param b, expected result>
private static readonly Tuple<int, int, int>[] TestData = new Tuple<int, int, int>[]{
    new Tuple<int, int, int>(0,0,0),
    new Tuple<int, int, int>(2,3,6),
    new Tuple<int, int, int>(1,0,0), //These will trigger one of the bugs
    new Tuple<int, int, int>(-2,-3,6),
    new Tuple<int, int, int>(0,1,0) //These will trigger one of the bugs
};
[TestMethod]
public void TestMultiply()
{
    foreach (var data in TestData)
    {
        Assert.AreEqual(data.Item3, Multiply(data.Item1, data.Item2),
                        "Failed for input ({0}, {1})", data.Item1, data.Item2);
    }
}

Running the test will surface only one of the bugs, the one triggered by the input (1,0):

This is not only bad because it doesn’t give a complete overview of the bugs but it also violates the principle of one assertion per test because more than one assertion could be triggered in the test case above.

The T4 approach (dynamic test)

Read the rest of this post »

Fun with Batch files

(-1 rating, 1 votes)

Feb 12th, 2011

It goes like this: create a small script that will take the files from a folder (only the top folder, not the sub directories) and will copy them to Program Files (32 bit). How hard can it be?

Well… If you have a programming background and you like to format the code then, such a task takes 1 hour, otherwise… 5 minutes.

So, I wrote a batch file (just part of it displayed here):

SET /P config=Configuration to deploy (1 = Debug; 2 = Release):
ECHO Setting up folders...
SET instpath = %ProgramFiles(x86)%
IF %config% == 1 (set drop = source\bin\x86\Debug)
IF %config% == 2 (set drop = bin\x86\Release)

Which is incorrect. Can you spot the mistake?

I will highlight one of the lines for you, maybe you can spot it then.

SET /P config=Configuration to deploy (1 = Debug; 2 = Release):
ECHO Setting up folders...
SET instpath = %ProgramFiles(x86)%
IF %config% == 1 (set drop = source\bin\x86\Debug)
IF %config% == 2 (set drop = bin\x86\Release)

Another hint: lines 5, 6 and 7 are incorrect.

Let me fix it and maybe you’ll see the problem.
Read the rest of this post »

Bug in SkypeGadget

(0 rating, 0 votes)

Jan 22nd, 2011

There is a bug in the Skype client that affects SkypeGadget. See status and workaround here.

Sorry for the inconvenience!

Christmas 2010

(0 rating, 0 votes)

Dec 24th, 2010

This is the first Christmas that I’m spending without my family. This is both good and bad. Is obvious why is bad but is good because I had the chance to know how is to do it different.

First of all, yesterday, which was my last for day for the year 2010, together with a few colleagues, we made snowmen in the MDCC campus. Those that saw them, categorized them as sincerely as possible as “the ugliest snowmen ever” but we are proud of them. The snow was really soft and it was impossible to make snow balls so we had to improvise.

Today, I celebrated Christmas together with 3 friends, 2 from India and one from Bangladesh. It was a little strange because I am the only one celebrating Christmas; for them is just free day :-) We cooked some Indian food – chicken, rice and something yellow that I don’t remember how is called – , drink some wine and laughed a lot. To my best surprise, the food was not as spicy as I was expecting and it was extremely delicious.

In a few days I’m going to Romania to see my friends and my relatives. However, I will not see my parents because they are in another country…

In the end, I wish you all:

And I leave you with a comic:

OneNote Anywhere

(0 rating, 0 votes)

Nov 8th, 2010

I like OneNote. I use it to store different code snippets and links to tech pages with useful information. It is not the ideal tool for doing this – IMO there is no tool, yet, that can replace a physical notebook – but I got used to it. Especially I enjoy the search feature because is impossible to do it on paper.

Until a few months ago, a solution for sharing the notebook between PCs was Mesh (or DropBox, or similar services), solution about which I wrote here. Since Office Live, this task was simplified – not that it was complicated before. With Office Live you can now save the notebooks online and edit them directly. Moreover, it allows sharing notebooks between computers connected to the Internet.

To do this you need a SkyDrive account (actually a LiveID). Then you can go on the website and create a new notebook. Give it a name and add information in it;do (almost) whatever you were doing in the OneNote client.

Now, if you choose Open in OneNote it will add that notebook to the application and… the best part… it will keep it synchronized with the live version.  You still have a local copy but if you lose it, only the changes since the last sync are gone – if  you are connected to the Internet then the last sync is, probably, 2 minutes ago. If you change the notebook in one place (on the website or in the local application), the changes will be reflected everywhere.

You can open the notebook on two or more computers and it will be updated on all of them. Even if one of them is offline, the changes are stored on the Internet and when you connect, you get the updated version.

Where is Victor?

(+1 rating, 1 votes)

Sep 18th, 2010

Hello there,

It’s been quite a while since my last post. A lot of things changed in my life since then; well, a little before that post. First of all, I moved to Denmark. Here, I’m doing an internship at Microsoft (Development Center Copenhagen). More specifically, I am a SDET working with the Dynamics AX team. Even more specifically, I test the developers tools from Dynamics AX.

Secondly, in 3 months, I moved two times. First from Netherlands to Denmark and then I switched place one more time because I was too far from my workplace. I really hate this activity but nothing can be done… And… I will move once more before the end of the year :(

I also started my master thesis project. (Hopefully) The outcome will be a really nice tool for Visual Studio (but not only). It will help developers and testers to find faster/reduce the number of bugs and will reduce the development time/costs. That’s all I’m revealing for the moment.

Least but not last, Copenhagen. In some sense, the city is both beautiful and ugly. Is a strange combination of modern and classic. A classical looking city with parks, rivers, boats, bridges and building with the same architecture, but having high speed trains, modern buses, shops and blinking commercials – that’s Copenhagen. It is filled with attractions (museums, theme parks, shopping places, events) but is really expensive (ex: the price for a beer in a crappy bar starts at 4-5 euros).  I didn’t have too much time for sightseeing but I managed to make a panorama picture (see below).

Read the rest of this post »

Modifying .NET binaries – Part 2

(+2 rating, 4 votes)

Jul 21st, 2010

Description
ObjectiveRemove the ‘Trial protection’ from an obfuscated .NET application
Tools
  • WinDbg
  • CFF Explorer
Target audienceAdvanced users

The second part of the article discusses how to modify binaries that are obfuscated. For simplicity and clarity, I will not use obfuscated binaries. Doing this, allows the reader to understand what is actually happening. In the demo I will completely ignore the name of the methods or the actual, non-obfuscated, code.

I recommend reading the first part, if you didn’t already. It provides some information that might be needed to understand theis second part.

The same ‘TrialApp.exe’ binary is used. The current approach, as opposed the the former one, is:

  1. Load the application in debugger and break the execution when the trial message is displayed.
  2. Get the call stack
  3. Find the address of the trial check method
  4. Remove the call

1. Load the application in debugger and break the execution when the trial message is displayed

WinDbg can be obtained for free from Windows SDK (see the Microsoft Downloads website). If you are running a 64 bit OS, make sure you start the 32bit version of WinDbg (should be in Program Files (x86)).

Load ‘TrialApp.exe’ in WinDbg by clicking File -> Load Executable. In order to run it you have 3 options:

  1. Type ‘g’ and press ENTER
  2. Press F5
  3. Click Debug -> Go

The application will start and the execution will stop when the message box is displayed. Is actually waiting for the user to click OK. At this point break the execution by pressing Debug -> Break.

Before being able to debug the .NET application, 2 DLLs needs to be loaded. They help the debugger ‘understand’ the .NET internals. The actual paths might differ on your configuration. Anyway, make sure you load the 32 bit version of these files (the 64 bit version are in the Framework64 folder). The .load command loads external libraries.

.load c:\Windows\Microsoft.NET\Framework\v4.0.30319\SOS.dll
.load c:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll

Read the rest of this post »

They finally merge

(+3 rating, 3 votes)

Jun 26th, 2010

Online software is nice because it allows you to have your documents (of any form) available anywhere is Internet access. However, you end up being forced to use a lot of services and, the worst part, they never interact.

For example: I was using Microsoft Live Mesh in order to synchronize and backup my files with the cloud. But MS also offered the Office Workspaces where you could store documents. So, I was using 2 services but it was impossible to edit/view a document from Mesh in the SharePoint workspace.

Another example is SkyDrive, with the new feature for editing documents (Office Live Apps). A nice addition, but my documents were in Mesh, not in SkyDrive. So, again, I had everything except the interaction between applications.

I am really excited to say it: they finally (started to) merge all the services! Seems that SkyDrive will the place where everything goes merged:

  • SkyDrive offers 25 GB for storage
  • Live Mesh will be replaced by Live Sync, which will upload the files on SkyDrive (just 2 out of 25 GB storage limit – strange)
  • Office 2010 supports loading and saving from and to SkyDrive
  • Office Live Apps are on SkyDrive and documents uploaded through Sync can be edited there Seems that synced files cannot be edited :(
  • Live Workspace will be replaced (integrated?) by Office Live Apps

With the Outlook connector I can keep my calendar, contacts and e-mail synchronized with the same cloud. Hopefully a feature for synchronizing tasks will be added soon. Also, mobile synchronization is a must – for my WM phone.

Is really nice that MS is doing a homogeneous environment where everything can be accessed from everywhere. However, the integration is not complete and it would be nice if they could integrate everything from My Phone to Messenger and social networks. Just imagine a single place from where you can do everything without being forced to use many services… [I'm dreaming, right?]

Modifying .NET binaries – Part 1

(+3 rating, 7 votes)

May 30th, 2010

The content of this post can be used for good and bad purposes. Modifying the source code to bypass trial/license checks is what crackers do in order to get paid software for free. Be advised that the purpose of this article is not to teach you how to steal. My target for this article are the .NET developers who should understand what a cracker will (try to) do in order to get access to paid features.

Before reading any further you should understand that each protection measure (as long as the cracker can access the source code) is useless. Is just a matter of time, for a motivated person, before she will bypass any protection.

For the demo, we are going to use a very simple Windows Forms Application that will display a message box with a trial message and will exit after that. The goal is to show a few techniques that will prevent the application from exiting (and will remove the trial message).

The code for the ‘trial’ application is kept in just one class. There is just one variable for checking the trial and we’ll consider that is always true – it makes no difference if there was a function call to determine if the trial has expired.

public partial class Form1 : Form
{
    bool hasExpired = true;
    public Form1()
    {
        InitializeComponent();
    }
    private void Form1_Load(object sender, EventArgs e)
    {
        CheckTrialApp();
    }
    private void CheckTrialApp()
    {
        if (hasExpired)
        {
            MessageBox.Show("Trial has expired");
            Application.Exit();
        }
    }
}

The binary used was compiled on the x86 Release configuration with VS2010 having .NET 4.0 as target framework. The IL Disassembler from VS2010 and a free application called CFF Explorer are used to view and edit the binary.

Read the rest of this post »

SVN: “no ancestry information”

(+2 rating, 2 votes)

May 29th, 2010

I got into a nasty problem today. While trying to commit the code in a SVN repository I got an error saying “no ancestry information”.

It took me a few (good) minutes and some searches on the Internet to find the solution for this problem. It seems that the SVN commit is forbidden if you try to commit a file that is a  folders structure, and one of the nodes in it (not the top most parent) is missing the .svn folder.

- folder1 [with .svn]
   - folder2 [without .svn]
      - folder3 [with .svn]

Committing “folder3″ will bring that error message. Couldn’t find the reason for this but, in my opinion, this is because the commit will try to update the “.svn” folders in the parent directories and will find a gap in this hierarchy.

« Older Posts Newer Posts »