| 1 | // Licensed to the .NET Foundation under one or more agreements. | 
|---|
| 2 | // The .NET Foundation licenses this file to you under the MIT license. | 
|---|
| 3 | // See the LICENSE file in the project root for more information. | 
|---|
| 4 |  | 
|---|
| 5 | /*===================================================================== | 
|---|
| 6 | ** | 
|---|
| 7 | ** Source:    test1.c | 
|---|
| 8 | ** | 
|---|
| 9 | ** Purpose:   Test #1 for the vsprintf function. | 
|---|
| 10 | ** | 
|---|
| 11 | ** | 
|---|
| 12 | **===================================================================*/ | 
|---|
| 13 |  | 
|---|
| 14 | #include <palsuite.h> | 
|---|
| 15 | #include "../vsprintf.h" | 
|---|
| 16 |  | 
|---|
| 17 | /* | 
|---|
| 18 | * Notes: memcmp is used, as is strlen. | 
|---|
| 19 | */ | 
|---|
| 20 |  | 
|---|
| 21 | int __cdecl main(int argc, char *argv[]) | 
|---|
| 22 | { | 
|---|
| 23 | char checkstr[] = "hello world"; | 
|---|
| 24 | char buf[256] = { 0 }; | 
|---|
| 25 | int ret; | 
|---|
| 26 |  | 
|---|
| 27 | if (PAL_Initialize(argc, argv) != 0) | 
|---|
| 28 | { | 
|---|
| 29 | return(FAIL); | 
|---|
| 30 | } | 
|---|
| 31 |  | 
|---|
| 32 | testvsp(buf, _countof(buf), "hello world"); | 
|---|
| 33 |  | 
|---|
| 34 | if (memcmp(checkstr, buf, strlen(checkstr)+1) != 0) | 
|---|
| 35 | { | 
|---|
| 36 | Fail( "ERROR: expected \"%s\" (up to %d chars), got \"%s\"\n", | 
|---|
| 37 | checkstr, 256, buf); | 
|---|
| 38 | } | 
|---|
| 39 |  | 
|---|
| 40 | testvsp(buf, _countof(buf), "xxxxxxxxxxxxxxxxx"); | 
|---|
| 41 | ret = testvsp(buf, _countof(buf), "hello world"); | 
|---|
| 42 |  | 
|---|
| 43 | if (ret != strlen(checkstr)) | 
|---|
| 44 | { | 
|---|
| 45 | Fail( "ERROR: expected negative return value, got %d", ret); | 
|---|
| 46 | } | 
|---|
| 47 |  | 
|---|
| 48 | if (memcmp(checkstr, buf, ret) != 0) | 
|---|
| 49 | { | 
|---|
| 50 | Fail( "ERROR: expected %s, got %s\n", checkstr, buf); | 
|---|
| 51 | } | 
|---|
| 52 |  | 
|---|
| 53 | PAL_Terminate(); | 
|---|
| 54 | return PASS; | 
|---|
| 55 | } | 
|---|
| 56 |  | 
|---|