e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James/**
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James * The contents of this file are subject to the terms of the Common Development and
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James * Distribution License (the License). You may not use this file except in compliance with the
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James * License.
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James *
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James * specific language governing permission and limitations under the License.
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James *
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James * When distributing Covered Software, include this CDDL Header Notice in each file and include
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James * Header, with the fields enclosed by brackets [] replaced by your own identifying
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James * information: "Portions copyright [year] [name of copyright owner]".
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James *
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James * Copyright 2015 ForgeRock AS.
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James */
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James#include <stdio.h>
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James#include <string.h>
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James#include <setjmp.h>
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James#include "platform.h"
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James#include "am.h"
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James#include "utility.h"
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James#include "net_client.h"
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James#include "thread.h"
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James#include "cmocka.h"
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas Jamesstatic void test_log_callback(void *arg, char *name, int error) {
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James int *pcount = arg;
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James (*pcount)++;
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James printf("%s -> error %d (%s)\n", name, error, strerror(error));
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James}
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas Jamesvoid test_init_cleanup(void **state) {
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James int instance = 1;
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James int clearup_count;
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James clearup_count = 0;
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James assert_int_equal(am_remove_shm_and_locks(instance, test_log_callback, &clearup_count), AM_SUCCESS);
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James assert_int_equal(clearup_count, 0);
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James
5d0dcd9820c04ac52a150525298eaae50c8b3544Mareks Malnacs am_init(instance, NULL);
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James clearup_count = 0;
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James assert_int_equal(am_remove_shm_and_locks(instance, test_log_callback, &clearup_count), AM_SUCCESS);
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James#ifdef _WIN32
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James assert_int_equal(clearup_count, 0);
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James#else
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James assert_int_equal(clearup_count, 5);
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James#endif
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James clearup_count = 0;
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James assert_int_equal(am_remove_shm_and_locks(instance, test_log_callback, &clearup_count), AM_SUCCESS);
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James assert_int_equal(clearup_count, 0);
e0d98b5e6f4b658de5303bf8d74576d2555db68eNicholas James}