ckd_mul_or_die.c (2460B)
1/* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 20#include "assert-signal.h" 21 22#include <CUnit/CUnit.h> 23#include <guacamole/mem.h> 24#include <stdint.h> 25 26/** 27 * Test which verifies that guac_mem_ckd_mul_or_die() calculates zero values 28 * for all inputs involving at least one zero value. 29 */ 30void test_mem__ckd_mul_or_die_zero() { 31 32 CU_ASSERT_EQUAL(guac_mem_ckd_mul_or_die(0), 0); 33 CU_ASSERT_EQUAL(guac_mem_ckd_mul_or_die(0, 0), 0); 34 CU_ASSERT_EQUAL(guac_mem_ckd_mul_or_die(0, 0, 0), 0); 35 CU_ASSERT_EQUAL(guac_mem_ckd_mul_or_die(0, 0, 0, 0), 0); 36 CU_ASSERT_EQUAL(guac_mem_ckd_mul_or_die(0, 0, 0, 0, 0), 0); 37 38 CU_ASSERT_EQUAL(guac_mem_ckd_mul_or_die(0, 1), 0); 39 CU_ASSERT_EQUAL(guac_mem_ckd_mul_or_die(1, 0), 0); 40 CU_ASSERT_EQUAL(guac_mem_ckd_mul_or_die(3, 2, 0), 0); 41 CU_ASSERT_EQUAL(guac_mem_ckd_mul_or_die(5, 0, 8, 9), 0); 42 CU_ASSERT_EQUAL(guac_mem_ckd_mul_or_die(99, 99, 99, 0, 99), 0); 43 44} 45 46/** 47 * Test which verifies that guac_mem_ckd_mul_or_die() successfully calculates 48 * expected values for relatively small integer inputs. 49 */ 50void test_mem__ckd_mul_or_die_small() { 51 CU_ASSERT_EQUAL(guac_mem_ckd_mul_or_die(123), 123); 52 CU_ASSERT_EQUAL(guac_mem_ckd_mul_or_die(123, 456), 123 * 456); 53 CU_ASSERT_EQUAL(guac_mem_ckd_mul_or_die(123, 456, 789), 123 * 456 * 789); 54} 55 56/** 57 * Test which verifies that guac_mem_ckd_mul_or_die() behaves as expected for 58 * relatively large integer inputs. 59 */ 60void test_mem__ckd_mul_or_die_large() { 61 62 CU_ASSERT_EQUAL(guac_mem_ckd_mul_or_die(SIZE_MAX), SIZE_MAX); 63 64 ASSERT_SIGNALLED(SIGABRT, guac_mem_ckd_mul_or_die(123, 456, SIZE_MAX)); 65 ASSERT_SIGNALLED(SIGABRT, guac_mem_ckd_mul_or_die(SIZE_MAX / 2, SIZE_MAX / 2)); 66 67} 68