@@ -4532,6 +4532,204 @@ def test_stdlibs(self):
4532
4532
4533
4533
self.do_run(src, '*1*', force_c=True)
4534
4534
4535
+ def test_strtoll_hex(self):
4536
+ # tests strtoll for hex strings (0x...)
4537
+ src = r'''
4538
+ #include <stdio.h>
4539
+ #include <stdlib.h>
4540
+
4541
+ int main() {
4542
+ const char *STRING = "0x4 -0x3A +0xDEADBEEF";
4543
+ char *end_char;
4544
+
4545
+ // undefined base
4546
+ long long int l1 = strtoll(STRING, &end_char, 0);
4547
+ long long int l2 = strtoll(end_char, &end_char, 0);
4548
+ long long int l3 = strtoll(end_char, NULL, 0);
4549
+
4550
+ // defined base
4551
+ long long int l4 = strtoll(STRING, &end_char, 16);
4552
+ long long int l5 = strtoll(end_char, &end_char, 16);
4553
+ long long int l6 = strtoll(end_char, NULL, 16);
4554
+
4555
+ printf("%d%d%d%d%d%d\n", l1==0x4, l2==-0x3a, l3==0xdeadbeef, l4==0x4, l5==-0x3a, l6==0xdeadbeef);
4556
+ return 0;
4557
+ }
4558
+ '''
4559
+ self.do_run(src, '111111')
4560
+
4561
+ def test_strtoll_dec(self):
4562
+ # tests strtoll for decimal strings (0x...)
4563
+ src = r'''
4564
+ #include <stdio.h>
4565
+ #include <stdlib.h>
4566
+
4567
+ int main() {
4568
+ const char *STRING = "4 -38 +4711";
4569
+ char *end_char;
4570
+
4571
+ // undefined base
4572
+ long long int l1 = strtoll(STRING, &end_char, 0);
4573
+ long long int l2 = strtoll(end_char, &end_char, 0);
4574
+ long long int l3 = strtoll(end_char, NULL, 0);
4575
+
4576
+ // defined base
4577
+ long long int l4 = strtoll(STRING, &end_char, 10);
4578
+ long long int l5 = strtoll(end_char, &end_char, 10);
4579
+ long long int l6 = strtoll(end_char, NULL, 10);
4580
+
4581
+ printf("%d%d%d%d%d%d\n", l1==4, l2==-38, l3==4711, l4==4, l5==-38, l6==4711);
4582
+ return 0;
4583
+ }
4584
+ '''
4585
+ self.do_run(src, '111111')
4586
+
4587
+ def test_strtoll_bin(self):
4588
+ # tests strtoll for binary strings (0x...)
4589
+ src = r'''
4590
+ #include <stdio.h>
4591
+ #include <stdlib.h>
4592
+
4593
+ int main() {
4594
+ const char *STRING = "1 -101 +1011";
4595
+ char *end_char;
4596
+
4597
+ // defined base
4598
+ long long int l4 = strtoll(STRING, &end_char, 2);
4599
+ long long int l5 = strtoll(end_char, &end_char, 2);
4600
+ long long int l6 = strtoll(end_char, NULL, 2);
4601
+
4602
+ printf("%d%d%d\n", l4==1, l5==-5, l6==11);
4603
+ return 0;
4604
+ }
4605
+ '''
4606
+ self.do_run(src, '111')
4607
+
4608
+ def test_strtoll_oct(self):
4609
+ # tests strtoll for decimal strings (0x...)
4610
+ src = r'''
4611
+ #include <stdio.h>
4612
+ #include <stdlib.h>
4613
+
4614
+ int main() {
4615
+ const char *STRING = "0 -035 +04711";
4616
+ char *end_char;
4617
+
4618
+ // undefined base
4619
+ long long int l1 = strtoll(STRING, &end_char, 0);
4620
+ long long int l2 = strtoll(end_char, &end_char, 0);
4621
+ long long int l3 = strtoll(end_char, NULL, 0);
4622
+
4623
+ // defined base
4624
+ long long int l4 = strtoll(STRING, &end_char, 8);
4625
+ long long int l5 = strtoll(end_char, &end_char, 8);
4626
+ long long int l6 = strtoll(end_char, NULL, 8);
4627
+
4628
+ printf("%d%d%d%d%d%d\n", l1==0, l2==-29, l3==2505, l4==0, l5==-29, l6==2505);
4629
+ return 0;
4630
+ }
4631
+ '''
4632
+ self.do_run(src, '111111')
4633
+
4634
+ def test_strtol_hex(self):
4635
+ # tests strtoll for hex strings (0x...)
4636
+ src = r'''
4637
+ #include <stdio.h>
4638
+ #include <stdlib.h>
4639
+
4640
+ int main() {
4641
+ const char *STRING = "0x4 -0x3A +0xDEAD";
4642
+ char *end_char;
4643
+
4644
+ // undefined base
4645
+ long l1 = strtol(STRING, &end_char, 0);
4646
+ long l2 = strtol(end_char, &end_char, 0);
4647
+ long l3 = strtol(end_char, NULL, 0);
4648
+
4649
+ // defined base
4650
+ long l4 = strtol(STRING, &end_char, 16);
4651
+ long l5 = strtol(end_char, &end_char, 16);
4652
+ long l6 = strtol(end_char, NULL, 16);
4653
+
4654
+ printf("%d%d%d%d%d%d\n", l1==0x4, l2==-0x3a, l3==0xdead, l4==0x4, l5==-0x3a, l6==0xdead);
4655
+ return 0;
4656
+ }
4657
+ '''
4658
+ self.do_run(src, '111111')
4659
+
4660
+ def test_strtol_dec(self):
4661
+ # tests strtoll for decimal strings (0x...)
4662
+ src = r'''
4663
+ #include <stdio.h>
4664
+ #include <stdlib.h>
4665
+
4666
+ int main() {
4667
+ const char *STRING = "4 -38 +4711";
4668
+ char *end_char;
4669
+
4670
+ // undefined base
4671
+ long l1 = strtol(STRING, &end_char, 0);
4672
+ long l2 = strtol(end_char, &end_char, 0);
4673
+ long l3 = strtol(end_char, NULL, 0);
4674
+
4675
+ // defined base
4676
+ long l4 = strtol(STRING, &end_char, 10);
4677
+ long l5 = strtol(end_char, &end_char, 10);
4678
+ long l6 = strtol(end_char, NULL, 10);
4679
+
4680
+ printf("%d%d%d%d%d%d\n", l1==4, l2==-38, l3==4711, l4==4, l5==-38, l6==4711);
4681
+ return 0;
4682
+ }
4683
+ '''
4684
+ self.do_run(src, '111111')
4685
+
4686
+ def test_strtol_bin(self):
4687
+ # tests strtoll for binary strings (0x...)
4688
+ src = r'''
4689
+ #include <stdio.h>
4690
+ #include <stdlib.h>
4691
+
4692
+ int main() {
4693
+ const char *STRING = "1 -101 +1011";
4694
+ char *end_char;
4695
+
4696
+ // defined base
4697
+ long l4 = strtol(STRING, &end_char, 2);
4698
+ long l5 = strtol(end_char, &end_char, 2);
4699
+ long l6 = strtol(end_char, NULL, 2);
4700
+
4701
+ printf("%d%d%d\n", l4==1, l5==-5, l6==11);
4702
+ return 0;
4703
+ }
4704
+ '''
4705
+ self.do_run(src, '111')
4706
+
4707
+ def test_strtol_oct(self):
4708
+ # tests strtoll for decimal strings (0x...)
4709
+ src = r'''
4710
+ #include <stdio.h>
4711
+ #include <stdlib.h>
4712
+
4713
+ int main() {
4714
+ const char *STRING = "0 -035 +04711";
4715
+ char *end_char;
4716
+
4717
+ // undefined base
4718
+ long l1 = strtol(STRING, &end_char, 0);
4719
+ long l2 = strtol(end_char, &end_char, 0);
4720
+ long l3 = strtol(end_char, NULL, 0);
4721
+
4722
+ // defined base
4723
+ long l4 = strtol(STRING, &end_char, 8);
4724
+ long l5 = strtol(end_char, &end_char, 8);
4725
+ long l6 = strtol(end_char, NULL, 8);
4726
+
4727
+ printf("%d%d%d%d%d%d\n", l1==0, l2==-29, l3==2505, l4==0, l5==-29, l6==2505);
4728
+ return 0;
4729
+ }
4730
+ '''
4731
+ self.do_run(src, '111111')
4732
+
4535
4733
def test_atexit(self):
4536
4734
# Confirms they are called in reverse order
4537
4735
src = r'''
0 commit comments