summaryrefslogtreecommitdiff
path: root/src/pal/tests/palsuite/pal_specific/PAL_Initialize_Terminate/test2/pal_initialize_twice.cpp
blob: fc460bc1ada1556fa0e3af77d366e44e28f01918 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

/*=============================================================
**
** Source: pal_initialize_twice.c
**
** Purpose: Positive test of PAL_Initialize and PAL_Terminate APIs.
**          Calls PAL_Initialize twice to ensure that doing so
**          will not cause unexpected failures in the PAL. 
**          Calls PAL_Terminate twice to clean up the PAL.
**          

**
**============================================================*/
#include <palsuite.h>

int __cdecl main(int argc, char *argv[])
{
    /* Initialize the PAL environment */
    if (0 != (PAL_Initialize(argc, argv)))
    {
	return FAIL;
    } 

    /* Try calling PAL_Initialize again - should just increment the init_count. */
    if (0 != (PAL_Initialize(argc, argv)))
    {        
        // Call terminate due to the first PAL initialization.
        PAL_TerminateEx(FAIL);
        return FAIL;
    }        
      
    /* If both calls to PAL_Initialize succeed, then PAL_Terminate must be 
    called twice. The first call just decrements the init_count to 1. */

    PAL_Terminate();
    PAL_Terminate();
    return PASS;
}