510{
513 int i,
len, expected_len;
514
515 static const BOOL directly_encodable_table[] =
516 {
517 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0,
518 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
519 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1,
520 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1,
521 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
522 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
523 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
524 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0
525 };
526 static const char base64_encoding_table[] =
527 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
528
529 const struct
530 {
531
536
537 char expected_dst[16];
538 int chars_written;
540 }
542 {
543
544 {
545 {0x4F60,0x597D,0x5417,0}, -1, output, sizeof(output) - 1,
546 "+T2BZfVQX-", 11, 11
547 },
548
549 {
550 {0x4F60,0x597D,0x5417,0}, -2, output, sizeof(output) - 1,
551 "+T2BZfVQX-", 11, 11
552 },
553
554 {
555 {0x4F60,0x597D,0x5417,0}, -1, output, 10,
556 "+T2BZfVQX-", 10, 0
557 },
558
559 {
560 {0x4F60,0x597D,0x5417,0}, -1, output, 11,
561 "+T2BZfVQX-", 11, 11
562 },
563
564 {
565 {0x4F60,0x597D,0x5417,0}, -1, output, 12,
566 "+T2BZfVQX-", 11, 11
567 },
568
569 {
570 {0x4F60,0x597D,0x5417,0}, -1,
NULL, 0,
571#if defined(__REACTOS__) && defined(_MSC_VER)
572 {0}, 0, 11
573#else
574 {}, 0, 11
575#endif
576 },
577
578 {
579 {0x4F60,0x597D,0x5417,0}, -1, output, 0,
580#if defined(__REACTOS__) && defined(_MSC_VER)
581 {0}, 0, 11
582#else
583 {}, 0, 11
584#endif
585 },
586
587 {
588 {'h','e','l','l','o',0}, 2, output, sizeof(output) - 1,
589 "he", 2, 2
590 },
591
592 {
593 {0x4F60,0x597D,0x5417,0}, 2, output, sizeof(output) - 1,
594 "+T2BZfQ-", 8, 8
595 },
596
597 {
598 {0}, -1, output, sizeof(output) - 1,
599 "", 1, 1
600 },
601
602 {
603 {'h','e','l','l','o',0}, -1, output, 2,
604 "he", 2, 0
605 },
606
607 {
608 {0x4F60,0x0001,0}, -1, output, 2,
609 "+T", 2, 0
610 },
611
612 {
613 {0x4F60,0x0001,0}, -1, output, 3,
614 "+T2", 3, 0
615 },
616
617 {
618 {0x4F60,0x0001,0}, -1, output, 4,
619 "+T2A", 4, 0
620 },
621
622 {
623 {0x4F60,0}, -1, output, 1,
624 "+", 1, 0
625 },
626
627
628 {
629 {0x4F60,0x597D,0x5417,0}, -1, output, 9,
630 "+T2BZfVQX", 9, 0
631 },
632
633
634 {
635 {0x4F60,0}, -1, output, 4,
636 "+T2", 3, 0
637 },
638
639 {
640 {'+',0}, -1, output, 1,
641 "+", 1, 0
642 }
643 };
644
645
646 for (
i = 0;
i <= 0xFFFF;
i++)
647 {
652
653 memset(output,
'#',
sizeof(output) - 1);
654 output[sizeof(output) - 1] = 0;
655
657
659 {
660
661 expected_len = 5;
663 }
664 else if (
i <= 0x7F && directly_encodable_table[
i])
665 {
666
667 expected_len = 4;
669 }
670 else
671 {
672
673 expected_len = 8;
675 base64_encoding_table[(
i & 0xFC00) >> 10],
676 base64_encoding_table[(
i & 0x03F0) >> 4],
677 base64_encoding_table[(
i & 0x000F) << 2]);
678 }
679
680 ok(
len == expected_len,
"i=0x%04x: expected len=%i, got len=%i\n",
i, expected_len,
len);
682 "i=0x%04x: expected output='%s', got output='%s'\n",
i,
expected, output);
683 ok(output[expected_len] ==
'#',
"i=0x%04x: expected output[%i]='#', got output[%i]=%i\n",
684 i, expected_len, expected_len, output[expected_len]);
685 }
686
687
688
689 for (
i = 0;
i <= 0xFFFF;
i++)
690 {
695
696 memset(output,
'#',
sizeof(output) - 1);
697 output[sizeof(output) - 1] = 0;
698
700
702 {
703
704 expected_len = 13;
706 }
707 else if (
i <= 0x7F && directly_encodable_table[
i])
708 {
709
710 expected_len = 12;
712 }
713 else
714 {
715
716 expected_len = 11;
718 base64_encoding_table[8 | ((
i & 0xC000) >> 14)],
719 base64_encoding_table[(
i & 0x3F00) >> 8],
720 base64_encoding_table[(
i & 0x00FC) >> 2],
721 base64_encoding_table[((
i & 0x0003) << 4) | 2]);
722 }
723
724 ok(
len == expected_len,
"i=0x%04x: expected len=%i, got len=%i\n",
i, expected_len,
len);
726 "i=0x%04x: expected output='%s', got output='%s'\n",
i,
expected, output);
727 ok(output[expected_len] ==
'#',
"i=0x%04x: expected output[%i]='#', got output[%i]=%i\n",
728 i, expected_len, expected_len, output[expected_len]);
729 }
730
732 {
733 memset(output,
'#',
sizeof(output) - 1);
734 output[sizeof(output) - 1] = 0;
736
739
741 {
743 "tests[%i]: expected error=0x%x, got error=0x%lx\n",
745 }
747
749 {
751 "tests[%i]: expected dst='%s', got dst='%s'\n",
754 "tests[%i]: expected dst[%i]='#', got dst[%i]=%i\n",
756 }
757 }
758}