/* 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"

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)];
	int asrt;

	i[scl_index(3, 2)] = 32;
	SCL_ASSERT(SCL_ARRAY_AT(i, 2) == 32);

	SCL_ARRAY_AT(l, 3) = 43;
	SCL_ASSERT(l[scl_index(4, 3)] == 43);

	s[scl_index(5, 4)] = 54;
	SCL_ASSERT(SCL_ARRAY_AT(s, 4) == 54);

	SCL_ARRAY_AT(c, 5) = 65;
	SCL_ASSERT(c[scl_index(6, 5)] == 65);

#	undef SCL_SIZE_MAX
#	define SCL_SIZE_MAX 256
	b[scl_index(256 / sizeof(char), 256 / sizeof(char) - 1)] = SCL_SIZEOF(b) / 4;

	asrt = SCL_ARRAY_AT(b, 256 / sizeof(char) - 1) == SCL_SIZEOF(b) / 4;
	SCL_ASSERT(asrt);

	SCL_ARRAY_AT(a, 255) = 257;
	SCL_ASSERT(a[scl_index(256, 255)] == 257);
}

#if defined(START_FUNC) && (START_FUNC == 1)
#	undef START_FUNC
#	define START_FUNC test_safe_indexing
#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
