Journée Académiques 2005
I have the honor to be one of the speaker of the “Academic Days” event, my talk is about Aspect Oriented Programming on the .net framework.
I have to admit that i’m really impressed, I’ll meet there people like John Lefor, PM for the Phoenix project at MSR. It seems that we share some ideas on compiler design, I hope I’ll be able to talk with him a little. Serge Lidin, the author of Inside .NET IL Assembler, and the writer of ildasm, ilasm, peverify, ..., will be here too, talking about the the evolution of the CIL. Be sure I’ll hear carefully ! Should be 3 exciting days ! All details here.
Cecil talks 4
A long time I have not blogged. Mainly spent my time working on Cecil. Better than a long talk, here is an example of what Cecil is able to do now. There is a name for programs that write themselves, I’ve forget it, and my example is not really one of them. My example is a very simple C# console program, but it will print its CIL representation, almost like ildasm.
I’ve not included the source and the result on the blog, because they are not really short. The source is viewable here : C# source. We simply load an assembly using Cecil, then we print the content of the methods. Easy no ? Let’s take a look at the output : here.
I have still a lot of work to do, and the API is not really stable, but I’m close to what I want. Once I’ll get it, I think I’ll call for contribution on this blog, to achieve the writing part of Cecil. Stay tuned !
GBrowser, online demo 1
Everyone is talking about that. Google is hiring a lot of FireFox developers.
This is the buzz of the beginning of the year. Google is already on your desktop, now, it intends to control your main application: the internet browser. You can read some more stuff here for example.
Once again, people are talking a lot, sometimes without even knowing what is really happening.
Do not wonder on how I get it, but the fact are there, I’ve an online demo of the next gen browser by our favorite search engine company. Go try it now !
GBrowser online demo
Ok, just kidding. I love Google’s work, please go on guys!
Thanks renaud for the nice, made in two minutes, icon.
White box unit testing with AspectDNG 5
Last time, Tom was kidding me (softly) about the fact that we can do almost everything we want with AspectDNG. I begin to think he wasn’t wrong…
Once again, here is a very, very complex system that should be hard tested:
<!- code formatted by http://manoli.net/csharpformat/ ->
<span class="rem">// Main.cs</span>
<span class="kwrd">using</span> System;
<span class="kwrd">public</span> <span class="kwrd">class</span> ComplexSystem {
<span class="kwrd">private</span> <span class="kwrd">int</span> m_secret;
<span class="kwrd">public</span> ComplexSystem() {
m_secret = 0;
}
<span class="kwrd">private</span> <span class="kwrd">void</span> SecretOperation(<span class="kwrd">int</span> oper) {
m_secret += oper;
}
<span class="rem">// should always return a multiple of 2</span>
<span class="kwrd">public</span> <span class="kwrd">int</span> PublicOperation() {
<span class="kwrd">if</span> ((m_secret % 2) != 0) {
SecretOperation(1);
}
<span class="kwrd">return</span> m_secret;
}
}
This can be safely compiled to a Main.dll.
Ok, this ComplexSystem is the central point of your next application, you NEED to test it. What can be better than NUnit ? But here is the problem, you would like to be sure that the secret operation have a correct behaviour, and that the m_secret field is well setted… Two way to do that, first you use boring Reflection, or you can even take a look behind your back, you ensure that you’re alone, you change the visibility of all this, but you promise yourself that you’ll change it as soon as tests passed. Also you may note that somewhere not to forgot, this is a SECRET operation.
What about introducing a new way of testing this ? Using AspectDNG ? Something I may call white box unit testing ? Here is one aspect to do that :
<!
<span class="rem">// Tests.cs</span>
<span class="kwrd">using</span> System;
<span class="kwrd">using</span> NUnit.Framework;
<span class="rem">// dummy complex system, may have been generated</span>
<span class="kwrd">public</span> <span class="kwrd">class</span> ComplexSystem {
<span class="kwrd">public</span> <span class="kwrd">int</span> m_secret;
<span class="kwrd">public</span> <span class="kwrd">void</span> SecretOperation(<span class="kwrd">int</span> oper) {}
<span class="kwrd">public</span> <span class="kwrd">int</span> PublicOperation() { <span class="kwrd">return</span> 0; }
}
[TestFixture]
<span class="kwrd">public</span> <span class="kwrd">class</span> TestComplexSystem {
<span class="kwrd">private</span> ComplexSystem m_complexSystem;
[SetUp]
<span class="kwrd">public</span> <span class="kwrd">void</span> SetUp() {
m_complexSystem = <span class="kwrd">new</span> ComplexSystem();
}
[Test]
<span class="kwrd">public</span> <span class="kwrd">void</span> TestPublicOperation() {
Assert.AreEqual(0, m_complexSystem.PublicOperation() % 2);
m_complexSystem.SecretOperation(1);
m_complexSystem.SecretOperation(1);
m_complexSystem.SecretOperation(1);
Assert.AreEqual(0, m_complexSystem.PublicOperation() % 2);
Assert.AreEqual(4, m_complexSystem.PublicOperation());
}
[Test]
<span class="kwrd">public</span> <span class="kwrd">void</span> TestFieldSecret() {
Assert.AreEqual(0, m_complexSystem.m_secret);
m_complexSystem.SecretOperation(1);
Assert.AreEqual(1, m_complexSystem.m_secret);
}
[Test]
<span class="kwrd">public</span> <span class="kwrd">void</span> TestSecretOperation() {
<span class="kwrd">int</span> cursor = m_complexSystem.m_secret;
m_complexSystem.SecretOperation(12);
Assert.AreEqual(12, m_complexSystem.m_secret - cursor);
}
}
What can we see there ? I use a dummy ComplexSystem, that looks like really close to the real one no ? It is just a trick, with that, I’ll be able to compile this single file into a Tests.dll assembly. Once this is done, all I have to do it to inject the content of my TestComplexSystem into the real ComplexSystem. This can be done with the standard MetaAspect Insert from AspectDNG.
When weaving is done, after using a simple insert advice, here is the result :

“Et voila”, the ComplexSystem is now a test fixture itself. Pretty simple no ?
And this sample works with Mono. Of course it is a very lightweight one, but hey, it looks good !
UPDATE: You can download the sources of the example here. Just compile as described in the post, and run AspectDNG -w on the AspectDNG.xml provided.
So, what do you think about this kind of unit testing ? I’m curious about you opinion !