~ubuntu-branches/ubuntu/precise/xulrunner-1.9/precise

« back to all changes in this revision

Viewing changes to mozilla/xpcom/tests/TestHarness.h

  • Committer: Bazaar Package Importer
  • Author(s): Alexander Sack
  • Date: 2009-06-03 10:04:36 UTC
  • mfrom: (1.1.20 upstream)
  • Revision ID: james.westby@ubuntu.com-20090603100436-e8am3r2lyj5z5931
Tags: 1.9.0.11+build2+nobinonly-0ubuntu1
* New upstream release v1.9.0.11 build2 (FIREFOX_3_0_11_BUILD2)
  - see USN-779-1
- adjust patches to changed upstream code base
  - update debian/patches/bz372826_att337031_about_style.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
 
38
38
/*
39
39
 * Test harness for XPCOM objects, providing a scoped XPCOM initializer,
40
 
 * nsCOMPtr, nsRefPtr, do_CreateInstance, and stdio.h/stdlib.h.
 
40
 * nsCOMPtr, nsRefPtr, do_CreateInstance, do_GetService, ns(Auto|C|)String,
 
41
 * and stdio.h/stdlib.h.
41
42
 */
42
43
 
43
44
#ifndef TestHarness_h__
44
45
#define TestHarness_h__
45
46
 
46
 
#include "nsIServiceManager.h"
47
47
#include "nsComponentManagerUtils.h"
 
48
#include "nsServiceManagerUtils.h"
48
49
#include "nsCOMPtr.h"
49
50
#include "nsAutoPtr.h"
 
51
#include "nsStringGlue.h"
50
52
#include <stdio.h>
51
53
#include <stdlib.h>
 
54
#include <stdarg.h>
 
55
 
 
56
/**
 
57
 * Prints the given failure message and arguments using printf, prepending
 
58
 * "FAIL " for the benefit of the test harness and appending "\n" to eliminate
 
59
 * having to type it at each call site.
 
60
 */
 
61
void fail(const char* msg, ...)
 
62
{
 
63
  va_list ap;
 
64
 
 
65
  printf("FAIL ");
 
66
 
 
67
  va_start(ap, msg);
 
68
  vprintf(msg, ap);
 
69
  va_end(ap);
 
70
 
 
71
  putchar('\n');
 
72
}
 
73
 
 
74
/**
 
75
 * Prints the given string followed by " PASSED!\n", to be used at the end
 
76
 * of a successful test function.
 
77
 */
 
78
void passed(const char* test)
 
79
{
 
80
  printf("%s PASSED!\n", test);
 
81
}
 
82
 
52
83
 
53
84
class ScopedXPCOM
54
85
{
62
93
      nsresult rv = NS_InitXPCOM2(&mServMgr, NULL, dirSvcProvider);
63
94
      if (NS_FAILED(rv))
64
95
      {
65
 
        printf("FAIL NS_InitXPCOM2 returned failure code %x\n", rv);
 
96
        fail("NS_InitXPCOM2 returned failure code 0x%x", rv);
66
97
        mServMgr = NULL;
67
98
      }
68
99
    }
75
106
        nsresult rv = NS_ShutdownXPCOM(NULL);
76
107
        if (NS_FAILED(rv))
77
108
        {
78
 
          printf("FAIL XPCOM shutdown failed with code %x\n", rv);
 
109
          fail("XPCOM shutdown failed with code 0x%x", rv);
79
110
          exit(1);
80
111
        }
81
112
      }