nsprpub/pr/tests/freeif.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/nsprpub/pr/tests/freeif.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,43 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +/*
    1.10 + * A test to see if the macros PR_DELETE and PR_FREEIF are
    1.11 + * properly defined.  (See Bugzilla bug #39110.)
    1.12 + */
    1.13 +
    1.14 +#include "nspr.h"
    1.15 +
    1.16 +#include <stdio.h>
    1.17 +#include <stdlib.h>
    1.18 +
    1.19 +static void Noop(void) { }
    1.20 +
    1.21 +static void Fail(void)
    1.22 +{
    1.23 +    printf("FAIL\n");
    1.24 +    exit(1);
    1.25 +}
    1.26 +
    1.27 +int main(int argc, char **argv)
    1.28 +{
    1.29 +    int foo = 1;
    1.30 +    char *ptr = NULL;
    1.31 +
    1.32 +    /* this fails to compile with the old definition of PR_DELETE */
    1.33 +    if (foo)
    1.34 +        PR_DELETE(ptr);
    1.35 +    else
    1.36 +        Noop();
    1.37 +
    1.38 +    /* this nests incorrectly with the old definition of PR_FREEIF */
    1.39 +    if (foo)
    1.40 +        PR_FREEIF(ptr);
    1.41 +    else
    1.42 +        Fail();
    1.43 +
    1.44 +    printf("PASS\n");
    1.45 +    return 0;
    1.46 +}

mercurial