/* Copyright 2016 Samsung Electronics Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include "scl/def.h"

#if defined(ARRAY_LEN_ERROR_1)
	void compile_error_1(void) {
		int *a;
		scl_size_t len = SCL_ARRAY_LEN(a);
		(void)len;
	}
#endif

#if defined(ARRAY_LEN_ERROR_2)
	void compile_error_2(int arr[19]) {
		scl_size_t len = SCL_ARRAY_LEN(arr);
		(void)len;
	}
#endif

#if defined(ARRAY_LEN_ERROR_3)
	void compile_error_3(void) {
		void *a;
		scl_size_t len = SCL_ARRAY_LEN(a);
		(void)len;
	}
#endif

#if defined(ARRAY_LEN_ERROR_4)
#	undef SCL_SIZE_MAX
#	define SCL_SIZE_MAX 256
	char array[SCL_SIZE_MAX + 1];
	void compile_error_4(void) {
		scl_size_t len = SCL_ARRAY_LEN(array);
		(void)len;
	}
#endif

#if defined(ARRAY_LEN_ERROR_5)
#	undef SCL_SIZE_MAX
#	define SCL_SIZE_MAX 256
	char array[(size_t)(SCL_SIZE_MAX) / sizeof(char) + 1];
	void compile_error_4(void) {
		scl_size_t len = SCL_SIZEOF(array);
		(void)len;
	}
#endif

static void do_tests(void) {
	int		i[3];
	long	l[4];
	short	s[5];
	char	c[6];
	short	a[256];
	char	b[256 / sizeof(char)];

	SCL_ASSERT(SCL_SIZEOF(i) == sizeof(i));
	SCL_ASSERT(SCL_ARRAY_LEN(i) == 3);

	SCL_ASSERT(SCL_SIZEOF(l) == sizeof(l));
	SCL_ASSERT(SCL_ARRAY_LEN(l) == 4);

	SCL_ASSERT(SCL_SIZEOF(s) == sizeof(s));
	SCL_ASSERT(SCL_ARRAY_LEN(s) == 5);

	SCL_ASSERT(SCL_SIZEOF(c) == sizeof(c));
	SCL_ASSERT(SCL_ARRAY_LEN(c) == 6);

	SCL_ASSERT(SCL_SIZEOF(c) > -1);
	SCL_ASSERT(SCL_ARRAY_LEN(c) > -1);

#	undef SCL_SIZE_MAX
#	define SCL_SIZE_MAX 256
	i[0] = SCL_SIZEOF(b);
	SCL_ASSERT(i[0] == sizeof(b));

	i[0] = SCL_ARRAY_LEN(a);
	SCL_ASSERT(i[0] == 256);
}


#if defined(START_FUNC) && (START_FUNC == 1)
#	undef START_FUNC
#	define START_FUNC test_size
#endif

#if defined(START_FUNC)
	extern void START_FUNC(void) {
		do_tests();
	}
#else
	extern int main(int argc, char const **argv) {
		do_tests();
		return 0;
	}
#endif
